Sunday 29 October 2023

Consider the inbuilt mtcar dataset i) Subset the vector, “mtcars[,1]“, for values greater than “15.0“. ii) Subset “airquality” for “Ozone” greater than “28“, or “Temp” greater than “70“. Return the first five rows. iii) Subset “airquality” for “Ozone” greater than “100“. Select the columns “Ozone“, “Temp“, “Month” and “Day” only.-Big data slip16

Consider the inbuilt mtcar dataset

i) Subset the vector, “mtcars[,1]“, for values greater than “15.0“.

ii) Subset “airquality” for “Ozone” greater than “28“, or “Temp” greater than “70“.

Return the first five rows.

iii) Subset “airquality” for “Ozone” greater than “100“. Select the columns “Ozone“,

“Temp“, “Month” and “Day” only.

 

data(mtcars)

data(airquality)

# 1. Subset the vector "mtcars[,1]" for values greater than 15.0

subset_mtcars <- mtcars[mtcars[, 1] > 15.0, ]

 

# 2. Subset "airquality" for "Ozone" greater than 28 or "Temp" greater than 70 and return the first five rows

subset_airquality_2 <- head(airquality[airquality$Ozone > 28 | airquality$Temp > 70, ], 5)

 

# 3. Subset "airquality" for "Ozone" greater than 100 and select the columns "Ozone," "Temp," "Month," and "Day" only

subset_airquality_3 <- airquality[airquality$Ozone > 100, c("Ozone", "Temp", "Month", "Day")]