Re: [R] calculate with different columns from different datasets

2013-09-01 Thread laro
Thank you, it worked! -- View this message in context: http://r.789695.n4.nabble.com/calculate-with-different-columns-from-different-datasets-tp4674918p4675116.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mail

Re: [R] calculate with different columns from different datasets

2013-08-30 Thread laro
Thank you a lot A.K.! One more question: I'd like to compute the Spearman's rank correlation coefficients for V1 (from dat1) and V1 (from dat2) and so on... Do you know how to do that? I managed to write the Pearson's correlation product moment coefficient with your sapply-approach, but I have no

Re: [R] calculate with different columns from different datasets

2013-08-30 Thread arun
],dat2[,i],method="spearman")) #[1] -1.000  0.500 -0.8660254 #or  diag(cor(dat1,dat2,method="spearman")) #    V1 V2 V3 #-1.000  0.500 -0.8660254 A.K. - Original Message - From: laro To: r-help@r-project.org Cc: Sent: Friday, August 3

Re: [R] calculate with different columns from different datasets

2013-08-29 Thread laro
Thank you for your answer. But further calculations will be much more difficult, like (1-b)^2 * Var(V1) for all matching columns where b is the slope from a regression V1 (from datset 1) on V1 (dataset 2) and Var(V1) the variance from V1(from dataset2). So what I'm looking for is somethi

[R] calculate with different columns from different datasets

2013-08-29 Thread laro
Hi thereI've got two datasets of the following form (just an example, the real dataset got a lot more columns)dataset1V1 V2 V32 6 84 3 41 9 8and dataset 2V1 V2 V36 8 42 0 78 1 3First, I'd like to calculate the followin

Re: [R] calculate with different columns from different datasets

2013-08-29 Thread arun
Hi, Try:  res<-sapply(seq_len(ncol(dat1)),function(i) setNames(((1-coef(lm(dat1[,i]~dat2[,i]))[2])^2)*var(dat2[,i]),NULL))  res #[1] 21.0 16.11842 18.69231 A.K. Thank you for your answer. But further calculations will be much more difficult, like (1-b)^2 * Var(V1)       for all matching

Re: [R] calculate with different columns from different datasets

2013-08-29 Thread arun
Hi, Try: dat1<- read.table(text=" V1 V2 V3 2 6 8 4 3 4 1 9 8 ",sep="",header=TRUE) dat2<- read.table(text=" V1 V2 V3 6 8 4 2 0 7 8 1 3 ",sep="",header=TRUE) res1<- as.matrix(dat1-dat2) res1 #    V1 V2 V3 #[1,] -4 -2  4 #[2,]  2  3 -3 #[3,] -7  8  5 res2<-t(t(dat1)-colMeans(dat2)) res2 #