[R] Newbie's question

Gabor Grothendieck ggrothendieck at gmail.com
Sun May 13 16:09:09 CEST 2007


On 5/13/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On Sun, 13 May 2007, Sarah Goslee wrote:
>
> > Sure, R can do anything. The first trick, though, is to learn
> > how to write clear-enough questions to the mailing list
> > that you get helpful answers back. A worked example of
> > what you want would be very useful, since I have no idea
> > what the index is, or what field2 is, or what kind of graph
> > you want. OS would also be helpful, since the example
> > I'm giving only works as written on linux.
> >
> > Still, one approach
> >
> > allfiles <- system("ls *.csv", intern=TRUE) # linux only
>
> Two better and almost completely portable replacements
>
> allfiles <- Sys.glob("*.csv") # R >= 2.5.0
> allfiles <- dir(".", pattern="\\.csv$")

Also:

dir(".", glob2rx("*.csv"))  # R >= 2.2.0

and prior to 2.2.0 with package sfsmisc.

>
>
> > allfield2 <- numeric(length(allfiles))
> > for(i in 1:length(allfiles)) {
> >   allfield2 <- read.table(allfiles[i])$field2
> >  # need read.table options, and correct way to get field2
> > }
> >
> > hist(allfield2); sd(allfield2)
> >
> > Sarah
> >
> > On 5/12/07, onthetopo <sweih at zodiac.chem.ubc.ca> wrote:
> >>
> >> Hi guys,
> >> I've brand new to the R scene.
> >> I have hundreds of csv files that has field 1 ,YYYY/MM/DD as index
> >> How to generate a graph of distribution and calculate the standard deviation
> >> of field2 for all of the files in a directory?
> >>
> >> I'm wondering if R could do this.
> >> Thanks a lot.
> >
> >
> >
>
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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