Hi Anand,

Try creating a variable where you can store your data, and append it in your
loop. See added lines of code to include below...

On Thu, Nov 4, 2010 at 9:43 AM, Anand Bambhania <amb1netwo...@gmail.com>wrote:

> Hi all,
>
> I am processing 24 samples data and combine them in single table called
> CombinedSamples using following:
>
> CombinedSamples<-rbind(Sample1,Sample2,Sample3)
>
> Now variables Sample1, Sample2 and Sample3 have many different columns.
>
> To make it more flexible for other samples I'm replacing above code with a
> for loop:
>
> #Sample is a string vector containing all 24 sample names
>

#create a variable to stick your results

res<- NULL

>
> for (k in 1:length(Sample))
> {
>      CombinedSamples<-rbind(get(Sample[k]))
>
      res<-c(res, CombinedSamples)

> }
>
> Now, every iteration of your loop should append CombinedSamples to res, and
you won't overwrite your results every time.

HTH,

Mike



> This code only stores last sample data as CombinedSample gets overwritten
> every time. Using "CombinedSamples[k]" or "CombinedSamples[k,]" causes
> dimension related errors as each Sample has several rows and not just 24.
> So
> how can I assign data of all 24 samples to CombinedSamples?
>
> Thanks,
>
> Anand
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to