r markdown练习

data(mtcars)
View(mtcars)
summary(mtcars)

efficient <- subset(mtcars,mpg>=23)
str(efficient)

logical operators in R:& |

subset(mtcars, mpg > 30 & hp > 100)
subset(mtcars, mpg < 14 | disp > 390)

subset(mtcars,qsec<=16.9)
lightCars <- subset(mtcars,wt<2)
lightCars

add a variable to a DataFrame

mtcars$year <- 1974
mtcars$year <- c(1973, 1974)

drop a variable

mtcars <- subset(mtcars, select = -year)

ifelse()语句

mtcars$wt
cond <- mtcars$wt < 3
cond
mtcars$weight_class <- ifelse(cond, 'light', 'average')
mtcars$weight_class
cond <- mtcars$wt > 3.5
mtcars$weight_class <- ifelse(cond, 'heavy', mtcars$weight_class)
mtcars$weight_class

delete variables from the work space.

rm(cond)
rm(efficient)

你可能感兴趣的:(r markdown练习)