[R] correlation matrix between data from different files

jeff6868 geoffrey_klein at etu.u-bourgogne.fr
Wed Apr 18 10:22:48 CEST 2012


I improved yesterday a bit your script (mostly according to station numbers
for the automatization). Here's the final version. thanks again! 

filenames <- list.files(pattern="\\_2008_reconstruit.csv$")

Sensors <- paste("capteur_", 1:4, sep="")

Stations <-substr(filenames,1,5)

nsensors <- length(Sensors)
nstations <- length(Stations)

nobs <- nrow(read.table(filenames[1], header=TRUE))

yr2008 <- array(NA, dim=c(nobs, nsensors, nstations))

for(i in seq_len(nstations)){
    tmp <- read.table(filenames[i], header=TRUE, sep=";")
    yr2008[ , , i] <- as.matrix(tmp[, Sensors])
}

dimnames(yr2008) <- list(seq.int(nobs), Sensors, Stations)
cor2008 <- lapply(Sensors, function(s) cor(yr2008[ , s,
],use="complete.obs"))
names(cor2008) <- Sensors
cor2008$capteur_1
cor2008$capteur_2
cor2008$capteur_3
cor2008$capteur_4

--
View this message in context: http://r.789695.n4.nabble.com/correlation-matrix-between-data-from-different-files-tp4552226p4567031.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list