[R] Need help creating multiple datasets using loops or vectorization

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun Dec 13 20:18:37 CET 2009


Forget the loop and use

vocallGrp <- split(vocallsub, vocallsub$Group)


Uwe Ligges


Anderson, Chris wrote:
> I am trying to create multiple dataset by group like the following using either a loop or vectorization:
> 
> vocallGp1<-subset(vocallsub, Group==1)
> vocallGp2<-subset(vocallsub, Group==2)
> vocallGp3<-subset(vocallsub, Group==3)
>  vocallGp4<-subset(vocallsub, Group==4)
>  vocallGp5<-subset(vocallsub, Group==5)
> 
> When I create the loop I get the following error:
> 
> vocallsub<-vocall[c("PatientID","Group")]
>> for(i in 1:length(vocallsub$Group)){vocallGrp[i]<-subset(vocallsub, Group==(i))}
> Error in vocallGrp[i] <- subset(vocallsub, Group == (i)) :
>   object 'vocallGrp' not found
> 
> This is my first time attempting to create a loop and am not sure what I am missing and I need assistance with the proper syntax.
> 
> 
> Chris Anderson
> Data Analyst
> Medical Affairs
> wk: 925-677-4870
> cell: 707-315-8486
> Fax:925-677-4670
> 
> 
> 
> 
> 
> This electronic message transmission, including any attachments, contains
> information which may be confidential, privileged and/or otherwise exempt
> from disclosure under applicable law. The information is intended to be for the
> use of the individual(s) or entity named above. If you are not the intended
> recipient or the employee or agent responsible for delivering the message
> to the intended recipient, you are hereby notified that any disclosure, copying,
> distribution or use of the contents of this information is strictly prohibited.  If
> you have received this electronic transmission in error, please notify the sender
> immediately by telephone (800-676-6777) or by a "reply to sender only"
> message and destroy all electronic and hard copies of the communication,
> including attachments.  Thank you.
> 
> For more information on Paradigm Management Services, LLC, please visit
> http://www.paradigmcorp.com
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list