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 Trieste

Try:

# 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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to