Sara
Sara

Reputation: 59

Applying a distance matrix to multiple data frames

I have 20 data frames of different lengths, but all the same number of columns. I would like to run some analyses, in this case a distance matrix using vegan, for each of these data frames. I have searched around and just figure I am missing a step somewhere.

dummy data is using 5 df, and I have been trying to use the lapply.

df1<- matrix(data = c(1:100), nrow = 10, ncol = 10)
df2<- matrix(data = c(1:150), nrow = 15, ncol = 10)
df3<- matrix(data = c(1:50), nrow = 5, ncol = 10)
df4<- matrix(data = c(1:200), nrow = 20, ncol = 10)
df5<- matrix(data = c(1:100), nrow = 10, ncol = 10)
Y<- list(df1, df2, df3, df4, df5)
Y.dc <- lapply(Y, dist.ldc(Y, "chord"))

I have also tried just running it on the list directly, and I keep getting errors there too.

Y.dc<- dist.ldc(Y, "chord")

Ideally, I would like to not run 20 lines/chunks of code for each frame. Eventually, I would also like to be able to generate nMDS plots, and run PERMANOVAs on each of the data frames all at once as well. Would I need to write/run a function in order to accomplish that?

Upvotes: 0

Views: 127

Answers (1)

py_b
py_b

Reputation: 189

A valid syntax :

Y.dc <- lapply(Y, dist.ldc, method = "chord")

(I assumed function dist.lc came from package adespatial, which I don't know)

Upvotes: 1

Related Questions