data(mtcars)
sset <- function(column){
mtcars$column}
Why does not this work? Basically, if I can select a column thus, I will be able to do a lot more. I know there are other ways to subset, but is this NOT workable at all?
You should use []
for subsetting with variables and arguments:
sset <- function(column) {
mtcars[,column]
}
sset("mpg")
#[1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 10.4
#[17] 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 15.0 21.4