[R] Newbie's question
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun May 13 15:58:23 CEST 2007
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$")
> 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
More information about the R-help
mailing list