Re: [R] macro in a loop

2009-03-21 Thread Le Wang
Thank you all for the help! Le On Sat, Mar 21, 2009 at 4:23 PM, Pankaj Chopra wrote: > data.year[j] <- > read.table(paste("c:/data/",year[j],".csv",sep=''),header=T,sep=",") > > > should do it. > > > > Le Wang wrote: >> >> Hi there, >> >> Thanks for your time in advance. >> >> I am trying to rea

Re: [R] macro in a loop

2009-03-21 Thread jim holtman
COnsider the use of a 'list': dataYear <- lapply(c(1940, 1950, 1960), function(.file){ read.table(paste("c:/data/", .file, '.csv', sep=''), header=TRUE, sep=',') }) The you can access your data: dataYear[['1940']] or dataYear$"1940" On Sat, Mar 21, 2009 at 3:53 PM, Le Wang wrote: > Hi th

Re: [R] macro in a loop

2009-03-21 Thread Pankaj Chopra
data.year[j] <- read.table(paste("c:/data/",year[j],".csv",sep=''),header=T,sep=",") should do it. Le Wang wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 <- read.table("c:/data/1940.csv",header=TRUE,sep=",") data.1950 <-

Re: [R] macro in a loop

2009-03-21 Thread Gabor Grothendieck
R does not directly support macros and I don't think that that is what you meant. Also we probably want to put the data frames in a list so we can easily operate over all of them later. (If these are time series also see read.zoo in the zoo package.) setwd("c:/data") filenames <- paste(year, "cs

Re: [R] macro in a loop

2009-03-21 Thread David Winsemius
Sorry. Not sure what you mean by macro not " protected." ?paste ?assign Perhaps: > filelist <- paste("c:\\data\\", year,".csv", sep="") > filelist [1] "c:\\data\\1940.csv" "c:\\data\\1950.csv" "c:\\data\\1960.csv" for (i in filelist) { assign( paste("data.", year[i], sep="") ,

Re: [R] macro in a loop

2009-03-21 Thread Jorge Ivan Velez
Hi again, My bad. Below solution had a typo :(Here is the "correct" one: year<-c(1940,1950,1960) for (i in y) assign(paste("data.",i,sep=""), read.table(paste("c:/data/",i,".csv",sep=""),header=TRUE,sep=",")) HTH, Jorge On Sat, Mar 21, 2009 at 4:01 PM, Jorge Ivan Velez wrote: > > De

Re: [R] macro in a loop

2009-03-21 Thread Jorge Ivan Velez
Dear Le, Try this: year<-c(1940,1950,1960) for (i in y) assign(paste("data.",i,sep=""), read.table("c:/data/i.csv",header=TRUE,sep=",")) data.1940 data.1950 data.1960 See ?assign for more details. HTH, Jorge On Sat, Mar 21, 2009 at 3:53 PM, Le Wang wrote: > Hi there,

[R] macro in a loop

2009-03-21 Thread Le Wang
Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 <- read.table("c:/data/1940.csv",header=TRUE,sep=",") data.1950 <- read.table("c:/data/1950.csv",header=TRUE,sep=",") data.1960 <- read.table("c:/data/1960.csv",header=TRUE