RE: [R] Assignments in loops

About this list Date view Thread view Subject view Author view Attachment view

From: Andy Bunn (abunn@montana.edu)
Date: Tue 30 Dec 2003 - 12:33:59 EST


Message-id: <000201c3ce75$11372cf0$78f05a99@msu.montana.edu>

Try assign - a la the subject heading.

I think this should work.

carmakes <- c('BMW','Chrysler','Citroen','Fiat','Ford','Holden','Honda',
 
'Mercedes','MG','Mitsubishi','Nissan','Peugeot','Renault','Subaru','Toyo
ta','VW')
for (i in 1:length(carmakes)) {
   # Create your path and file name
   fyle <- paste("c:/data/cars03/",carmakes[i],".txt",sep="")
   # Read fyle into a temp variable - replace everyhting after
   # <- with your read.table command.
   temp <- data.frame(x = runif(10), y = runif(10), z = runif(10))
   # Use assign to create the object
   assign(carmakes[i], temp)
}

HTH,
Andy

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 01 Jan 2004 - 09:21:04 EST