Skip to content

parsing files for plot

3 messages · Maxim, Baptiste Auguie

#
Hi again,

Below are two versions, depending on whether you want to use scan or read.table,

## with scan
library(reshape)
listOfFiles <- list.files()
d <- llply(listOfFiles, scan)
names(d) <- basename(listOfFiles)

melt(d)

## with read.table

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

library(plyr)
ldply(listOfFiles, read.table)


Note, I tested this code with the following files,

system("mkdir dummy")
setwd(paste(getwd(), "/dummy", sep=""))

files <- replicate(5, rnorm(sample(3:20, 1)), simplify=FALSE)
names <- paste("datafile", letters[1:5],".txt",  sep="")

l_ply(seq_along(files), function(ii, ...) write.table(x=files[[ii]],
file=names[ii], ... ),
      row.names = F, col.names = F)

HTH,

baptiste
On 30 January 2010 14:23, Maxim <deeepersound at googlemail.com> wrote: