[R] take data from a file to another according to their correlation coefficient

Rui Barradas ruipbarradas at sapo.pt
Wed Apr 25 16:15:28 CEST 2012


Hello,

The first is easy.

>
> How can I cut these files and save them automatically (one file for ST001,
> another for ST002, ...) according to these columns names?
> 

Similar to the way they were read, using lapply on the results list.
But first make a file names vector.
(I've used the file extension 'dat'.)


test <- process.all(lst, m)
fl.names <- paste(names(test), "dat", sep=".")
lapply(seq_len(length(test)), function(i) write.table(test[[i]],
fl.names[i], ...))


The second is trickier.

>
> And it is possible in your script to take the second best correlated
> station data
> instead of the best one, if there are NAs in this best correlated station
> at the same
> lines with the NA gaps of the station to fill?
>

In the function 'process.all', after the internal function 'f',
include the following.


g <- function(station){
	x <- df.list[[station]]
	if(any(is.na(x$data))){
		mat[row(mat) == col(mat)] <- -Inf
		nas <- which(is.na(x$data))
		ord <- order(mat[station, ], decreasing = TRUE)[-c(1, ncol(mat))]
		for(i in nas){
			for(y in ord){
				if(!is.na(df.list[[y]]$data[i])){
					x$data[i] <- df.list[[y]]$data[i]
					break
				}
			}
		}
	}
	x
}


Then, change the second pass to

	# Note that the two passes are different
	df.list <- lapply(seq.int(n), f)
	df.list <- lapply(seq.int(n), g)


And I come from Portugal. I'm a mathematician (with 6 semesters of stats).
When I go to France, it's more to Charente-Maritime - Cognac, I have friends
there,
and I'll definitelly have a couple of cognacs on you.
Good luck with your assignment.

Rui Barradas



--
View this message in context: http://r.789695.n4.nabble.com/take-data-from-a-file-to-another-according-to-their-correlation-coefficient-tp4580054p4586719.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list