syntax - R - How do I reference a variable by the column position? -
i have matrix / data frame of bunch of variables. how reference when setting formula?
example: let's have data set as:
data = read.csv(data_location, sep = ',')
and since it's high dimensionality don't spell out each column (which otherwise use c(col)). on lower dimensionality content i'd spell out each content. it's called target, left data[50].
fit <- rpart(target ~ ., data = train1, method = "anova")
i can't say
fit <- rpart(data[50] ~ ., data = train1, method = "anova")
as says "invalid type (list) variable 'data[50]'. how reference proper syntax?
data[, 50]
should work since data[50]
return data.frame (list) instead of contents of data.frame, need. try class(data[50])
, class(data[, 50])
see difference.
Comments
Post a Comment