# simple base R and simple dplyr operations # 0. determine your current working directory. Set your working directory to another directory getwd() # setwd("/Path/To/Dir...") # 1. investigate the functions c, data.frame, and setwd with the help function, for example ?c ?c ?data.frame ?setwd # 2. create a numeric vector named object consisting of the values #1,NA,3,4,67,98,43,NA,NA # 3. create another numberic vector named object2 consisting of the values 1,NA,3,4,67,98,43,NA,13 object <- c(1, NA, 3, 4, 67, 98, 43, NA, NA) object2 <- c(1, NA, 3, 4, 67, 98, 43, NA, 13) # 4. Investigate NA, the mode and the length of the 2 vectors, create a factor variable containing the following levels "small", "medium", "large" ?NA mode(object) mode(object2) length(object) length(object2) facvar <- factor(level = c("small", "medium", "large")) # 5. combine the 2 numeric vectors into a data frame named frame ob <- c(object,object2) # 6. install the tidyverse packages using install.packages install.packages("tidyverse") library(tidyverse) tidyverse_update() # 7. access the dataset mpg read about the data mpg #8. determine the average number of city miles per gallon for the data mean(unlist(mpg['cty'])) # 9. use the is.na function to find/locate NAs in object and object2 is.na(object) is.na(object2) # 10. use the na.omit function to remove the NAs from object and object2 object <- na.omit(object) object2 <- na.omit(object2) # 11. use the logical function to create a logical vector named tt of length 5 tt <- logical(5) # 12. calculate the sum of object sum(object) # 13. use the seq function to create the following sequence 5, 10, 15, 20 num5 <- seq(5,20,by=5) # 14. learn about the diamonds dataset using the help facility ?diamonds # 15. determine the number of columns and rows in the diamonds data set dim(diamonds) # 16 select the carat and price variables from diamonds carprice <- select(diamonds, carat, price) #17 select all columns but the x, y, z, and price columns select(diamonds, -x, -y, -z, -price) #18 find all diamonds with carat > .5 filter(diamonds, carat > .5) # 19. Create at least 2 other filter expressions for diamonds dataset use %in% filter(diamonds, cut %in% c('Ideal', 'Good')) head(diamonds) head(object)