Re: [R] Looping through R objects with $ operator and tags

2009-07-30 Thread Vivek Ayer
I figured it out. I understand that R isn't really meant to do this. Essentially, I want to have an object per read csv file which contains columns. But I'm dealing with hundreds of files in a folder and I wanted to automate the importing into R and process stuff without entering the shell and usin

Re: [R] Looping through R objects with $ operator and tags

2009-07-30 Thread Vivek Ayer
Got that work! Thanks. However, now I need to know how to dump tag values into an object, e.g., TotLogDist <- c(object1$LogDist,object2$LogDist,object3$LogDist ...) [for how many ever objects you provided] Is there a way to loop that? TotLogDist <- NULL for (i in c(1:10)) TotLogDist <- c(TotLog

Re: [R] Looping through R objects with $ operator and tags

2009-07-30 Thread baptiste auguie
essentially the same, object1 = object2 = object3 = data.frame(Distance = 1:10) foo = function(o){ within(get(o), LogDist <- log10(Distance)) } my.objects = paste("object", 1:3,sep="") lapply(my.objects, foo) It is however advisable to group the initial objects

Re: [R] Looping through R objects with $ operator and tags

2009-07-30 Thread jim holtman
I would first put the objects in a 'list' since it is easier to work with and then use 'lapply': > obj1 <- obj2 <- obj3 <- data.frame(Distance=1:10) > # create a list - earier to work with > list.obj <- list(obj1, obj2, obj3) > > list.obj <- lapply(list.obj, function(x){ + x$LogDist <- log(x$D

[R] Looping through R objects with $ operator and tags

2009-07-30 Thread Vivek Ayer
Hi all, Suppose I want to set the values in a column to the log of the values of another column like so: object$LogDist <- log10(object$Distance) How do I loop through the objects if I have object1, object2, etc to perform this function? object1$LogDist <- log10(object1$Distance) object2$LogDis

Re: [R] Looping through R objects

2009-07-28 Thread Steve Lianoglou
On Jul 28, 2009, at 5:39 PM, Vivek Ayer wrote: That just creates one object and doesn't contain any $ subobjects in it. Here's what I did to figure it out (It's complicated): for(i in c(1:13)) assign (paste ("bc",i,sep=""),read.csv(paste(i,".csv",sep=""),sep="",header=TRUE)) in shorthand: for

Re: [R] Looping through R objects

2009-07-28 Thread Rolf Turner
On 29/07/2009, at 9:39 AM, Vivek Ayer wrote: That just creates one object and doesn't contain any $ subobjects in it. Here's what I did to figure it out (It's complicated): for(i in c(1:13)) assign(paste("bc",i,sep=""),read.csv(paste (i,".csv",sep=""),sep="",header=TRUE)) in shorthand: for

Re: [R] Looping through R objects

2009-07-28 Thread Vivek Ayer
That just creates one object and doesn't contain any $ subobjects in it. Here's what I did to figure it out (It's complicated): for(i in c(1:13)) assign(paste("bc",i,sep=""),read.csv(paste(i,".csv",sep=""),sep="",header=TRUE)) in shorthand: for {assign(paste,read(paste))} This creates individual

Re: [R] Looping through R objects

2009-07-28 Thread Steve Lianoglou
Hi, On Jul 28, 2009, at 4:54 PM, Vivek Ayer wrote: Hi all, I have 13 csv files and I want to assign each csv file to one object, i.e., bc1 <- read.csv("1.csv,header=TRUE,sep="") bc2 <- read.csv("2.csv,header=TRUE,sep="") bc3 ... So I want to create 13 objects. How could I automate this wi

[R] Looping through R objects

2009-07-28 Thread Vivek Ayer
Hi all, I have 13 csv files and I want to assign each csv file to one object, i.e., bc1 <- read.csv("1.csv,header=TRUE,sep="") bc2 <- read.csv("2.csv,header=TRUE,sep="") bc3 ... So I want to create 13 objects. How could I automate this with a for loop? for (i in c(1:13)) ... Any ideas? Thanks