[R] parsing files for plot

baptiste auguie baptiste.auguie at googlemail.com
Sat Jan 30 13:33:47 CET 2010


Hi,

Hadley recently proposed a strategy using plyr for a very similar problem,

listOfFiles <- list.files()
names(listOfFiles) <- basename(listOfFiles)

library(plyr)
d <- ldply(listOfFiles, scan)

Even if you don't want to use plyr, it's always better to group things
in a list rather than clutter your workspace with lots of assign()ed
variables.

HTH,

baptiste


On 30 January 2010 13:19, Maxim <deeepersound at googlemail.com> wrote:
> Hi,
>
> I have many files containing one column of data. I like to use the scan
> function to parse the data. Next I like to bind to a large vector.
> I try this like:
>
> count<-1
> files <- list.files()  # all files in the working directory
> for(i in files) {
>
>       tmp <- scan(i)
>       assign(files[count], tmp)
>      count<-count+1
> }
>
> This part works!
>
> Now I like to plot the data in a boxplot.
>
> Usually I do this from individual vectors like:
>
> comb <- data.frame(dat = c(vector1, vector2 ......), ind = c(rep('vector1',
> length(vector1)).......))
> boxplot(dat ~ ind, data = comb)
>
> But how do I do this i a loop?
>
> I know the vector names (according to the filenames in the working
> directory), but I do not how to access them in my R code after having
> assigned the names.
>
> I guess the "lapply" or "dply" from the plyr library can do this, but I seem
> not to be able to do it.
>
> Is there a way to do this?
>
> gma
>
>        [[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