[R] how to combine data of several csv-files

Antje niederlein-rstat at yahoo.de
Mon Jul 30 10:00:25 CEST 2007


Hello,

I'm looking for a solution for the following problem:

1) I have a folder with several csv files; each contains a set of 
measurement values
2) The measurements of each file belong to a position in a two 
dimensional matrix (lets say "B02.csv" belongs to position 2,2
3) The size of the matrix is fix
4) I cannot assure to have a csv file for each position
5) Each position belongs to one category; This information is available 
in a file (means 2,2 and 2,3 may belong to category "c1"; 3,2 and 3,3 
may belong to category "c2")

Now, I process each available file and get a vector of 6 values or NA back.

The aim is to calculate mean and sd for vectors (element wise) coming 
from the same category (means if vec1 <- c(1,2,3,4,5,6) and vec2 <- 
c(6,7,8,9,10,11) belong to the same category, I would like to get mean 
<- c(3.5, 4.5, 5.5, 6.5, 7.5, 8.5))

... but I'm not sure how to proceed. I end up with a list containing 
these vectors for each processed file and I don't know how to combine 
them easily...

Does anybody have a suggestion for me?

What I've got so far:

folder <- choose.dir(getwd(), "Choose folder containing csv files")
setwd(folder)

rowString <- LETTERS[1:8]; cols <- 12

mat <- outer(rowString, formatC(seq(2,length=cols), flag = "0", width = 
2), paste, sep = "")
mat <- paste(mat, ".csv", sep = "_")

layoutfilename <- file.choose()
layoutfile <- read.csv(layoutfilename, sep=";", header=F, na.strings = "")

classmatrix <- sapply(layoutfile,as.character)
classes <- factor(classmatrix)

colnames(classmatrix) <- c(1:cols)
rownames(classmatrix) <- rowString

ret <- sapply(mat, calcHist)



More information about the R-help mailing list