Gabriele Stocco
2006-Nov-17 19:21 UTC
[R] applying cor.test in two different but matched dataframes
Dear R help, I have two dataframes with the same number of rows and columns. Each column is for a patient, each row for a variable. The columns and rows are matched in the two dataframes, so that each patient (column) and each variable (row) has the same position in the two dataframes. The values are different since each dataframe reports data from a different way to measure the same variables in the sampe patients. How can I make a cor.test, applying the function row by row in the two different dataframes, possibly without merging them? Thanks, Gabriele Stocco University of Trieste
Mark Lyman
2006-Nov-17 21:40 UTC
[R] applying cor.test in two different but matched dataframes
Gabriele Stocco <stoccog <at> units.it> writes:> > Dear R help, > I have two dataframes with the same number of rows and columns. Each > column is for a patient, each row for a variable. The columns and rows > are matched in the two dataframes, so that each patient (column) and > each variable (row) has the same position in the two dataframes. The > values are different since each dataframe reports data from a > different way to measure the same variables in the sampe patients. > > How can I make a cor.test, applying the function row by row in the two > different dataframes, possibly without merging them? > > Thanks, > > Gabriele Stocco > University of TriesteTry: # Create Data Frames With Rows as Variables x<-as.data.frame(t(as.data.frame(matrix(rnorm(100),10)))) y<-as.data.frame(t(as.data.frame(matrix(rnorm(100),10)))) # Convert to Lists So that Each Element of List is a variable t.x<-as.list(as.data.frame(t(x))) t.y<-as.list(as.data.frame(t(y))) # Use mapply to apply function to the two lists; see ?mapply mapply(cor.test,t.x,t.y) Mark Lyman