I would like to iterate through a table and break it into relvant parts based on the number of visits. I have tried several things but cannot seem to get it to work.
I have included the code.
for(i in 1:6){
paste("testing.visit",i,"\n",sep="") <- subset(testing,visit_no==2)
}
But I get the following error.
Error in paste("testing.visit", i, "\n", sep = "") <- subset(testing, :
target of assignment expands to non-language o开发者_如何学Cbject
Thank you,
Brandon
Try assign
inside the for
loop:
assign(paste("testing.visit", i, "\n", sep=""), subset(testing, visit_no==i))
You could also use dlply
(plyr
package ) to combine the subsets into a list:
library("plyr")
testing.visit <- dlply(testing, .(visit_no))
精彩评论