简体   繁体   English

将距离矩阵应用于多个数据帧

[英]Applying a distance matrix to multiple data frames

I have 20 data frames of different lengths, but all the same number of columns.我有 20 个不同长度的数据帧,但列数都相同。 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.虚拟数据使用 5 df,我一直在尝试使用 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.理想情况下,我不想为每帧运行 20 行/块代码。 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.最终,我还希望能够生成 nMDS 图,并同时在每个数据帧上运行 PERMANOVA。 Would I need to write/run a function in order to accomplish that?我是否需要编写/运行 function 才能做到这一点?

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) (我假设 function dist.lc 来自 package adespatial,我不知道)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM