【问题标题】:Running PCA on list of dataframes in R在 R 中的数据帧列表上运行 PCA
【发布时间】:2022-01-10 16:40:28
【问题描述】:

我有一个小问题。我有三个数据框,它们的列名彼此相同。我尝试使用 lapply 为这三个数据帧运行三个不同的 PCA。然而它没有用。我在这里附上了我的代码。任何帮助表示赞赏。

library(factoextra)
library(FactoMineR)
mtcars
listA<-mtcars%>%
  nest(-cyl)
listA$data # Here I created 3 list of dataframes based on cylinder capacity
lapply(listA$data,function(x[,1:6]) fviz_pca_biplot(PCA(x), label = "var",  # Then tried to run separate PCA for each list; selecting column 1:6 in each dataframe
                                          geom.ind="point",
                                          pointsize=4,
                                          alpha.ind = 0.8,
                                          col.ind =x[[9]], # Here I tried to make color by 'gear type"
                                          col.var = 'black',
                                          select.var = list(contrib=30),
                                          repel=TRUE,
                                          mean.point=FALSE,
                                          #habillage = as.factor(B$Class),
                                          theme_classic()))

【问题讨论】:

  • @akrun ,感谢您的帮助。我已经制作了一个可重现的示例并解释了我尝试过的内容。我已经尝试过你的建议。但是还不能修复。你有什么想法吗??谢谢
  • 尝试发布解决方案中的代码

标签: r list pca


【解决方案1】:

我们需要为theme_classic()指定参数名称,即ggtheme

out <- lapply(listA$data,function(x) fviz_pca_biplot(PCA(x[, 1:6]), label = "var",  # Then tried to run separate PCA for each list; selecting column 1:6 in each dataframe
                                           geom.ind="point",
                                           pointsize=4,
                                           alpha.ind = 0.8,
                                           col.ind = x[[9]], # Here I tried to make color by 'gear type"
                                           col.var = 'black',
                                           select.var = list(contrib=30),
                                           repel=TRUE,
                                           mean.point=FALSE,
                                           habillage = as.factor(x[[9]]),
                                           ggtheme = theme_classic()))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 2015-05-16
    相关资源
    最近更新 更多