Monday, 15 August 2011

col - R: substract the Y column as a matrix -



col - R: substract the Y column as a matrix -

i have table called test (imported read.csv) looks this:

y x1 x2 ... x100 0 125 ... 32 1 163 b ... 25 0 758 b ... 587

i have succeeded saving predictors in different table next command:

x_test <- test[, !(colnames(test) %in% c("y"))]

when type

fix(x_test)

i beautiful table predictors. cannot seem same y. help?

hope helpful. insufficient rep inquire info in comment, i'll jump in something. don't know class loaded object (or columns therein), might seek ensuring it's info frame, using subset:

#create random nonsense set.seed(123) junk1 = data.frame(matrix(rnorm(100,5,.5),ncol=1,nrow=100)) junk2 = data.frame(matrix(1:100,ncol=100,nrow=100)) colnames(junk1)="y" test=cbind(junk1,junk2) #should @ point have data.frame data, first column y, rest x1..x100 #if yours isn't already, after doing "test=read.csv(file)" "test=as.data.frame(test)" x_test = subset(test,select=colnames(test)[colnames(test)!="y"]) y_test = subset(test,select="y")

using subset may not best way, has advantage when extracting single column (as in case of "y") result info frame, rather vector.

edit: props sven saw enquired class (didn't see before posting this)

r col

No comments:

Post a Comment