R:如果另一个列中的行缺少值,则如何在另一列的列中提取值名和另一列的列名
我不确定该如何言语,或者是否可能会说,但是目标是从第1列获得类名,以及具有NA的行的列名
是一些数据的片段:
library(mlbench)
data(Soybean)
Soybean <- Soybean %>% as.data.frame(row.names = 1:nrow(.))
Soybean[c(32:39),]
Class date plant.stand precip temp hail crop.hist area.dam sever seed.tmt germ
32 phytophthora-rot 1 1 2 1 <NA> 3 1 <NA> <NA> <NA>
33 phytophthora-rot 2 1 2 2 <NA> 2 1 <NA> <NA> <NA>
34 phytophthora-rot 1 1 2 0 0 2 1 2 1 1
35 phytophthora-rot 2 1 2 2 <NA> 2 1 <NA> <NA> <NA>
36 phytophthora-rot 3 1 2 1 <NA> 2 1 <NA> <NA> <NA>
37 phytophthora-rot 0 1 1 1 0 1 1 1 0 0
38 phytophthora-rot 3 1 2 0 0 2 1 2 1 1
39 phytophthora-rot 2 1 1 1 <NA> 0 1 <NA> <NA> <NA>
所需的
32 phytophthora-rot hail
32 phytophthora-rot server
32 phytophthora-rot seed.tmt
32 phytophthora-rot germ
33 phytophthora-rot hail
33 phytophthora-rot sever
33 phytophthora-rot seed.tmt
33 phytophthora-rot germ
39 phytophthora-rot hail
39 phytophthora-rot server
:很快。 最终目标是查看缺少值的预测变量是否与它们所在的类有关。
我已经使用过
library(visdat)
vis_miss(Soybean)
,但这只是概述了丢失的数据,而无需提供类名称和关联的类名预测数据丢失的数据。 我还看到了建议 >,但这似乎是在假设我知道所有所需的值是什么。
I'm not sure how to word this, or if it's even possible, but the goal is to get the class name from column 1 and the column names for rows that have NA's
This is a snippet of some of the data:
library(mlbench)
data(Soybean)
Soybean <- Soybean %>% as.data.frame(row.names = 1:nrow(.))
Soybean[c(32:39),]
Class date plant.stand precip temp hail crop.hist area.dam sever seed.tmt germ
32 phytophthora-rot 1 1 2 1 <NA> 3 1 <NA> <NA> <NA>
33 phytophthora-rot 2 1 2 2 <NA> 2 1 <NA> <NA> <NA>
34 phytophthora-rot 1 1 2 0 0 2 1 2 1 1
35 phytophthora-rot 2 1 2 2 <NA> 2 1 <NA> <NA> <NA>
36 phytophthora-rot 3 1 2 1 <NA> 2 1 <NA> <NA> <NA>
37 phytophthora-rot 0 1 1 1 0 1 1 1 0 0
38 phytophthora-rot 3 1 2 0 0 2 1 2 1 1
39 phytophthora-rot 2 1 1 1 <NA> 0 1 <NA> <NA> <NA>
Desired:
32 phytophthora-rot hail
32 phytophthora-rot server
32 phytophthora-rot seed.tmt
32 phytophthora-rot germ
33 phytophthora-rot hail
33 phytophthora-rot sever
33 phytophthora-rot seed.tmt
33 phytophthora-rot germ
39 phytophthora-rot hail
39 phytophthora-rot server
and so on. The ultimate goal is to see if the predictors with missing values are related to the class they're in.
I have used
library(visdat)
vis_miss(Soybean)
but this just gives an overview of the missing data without providing the class names and the associated predictor with the missing data.
I also saw advice here, but it seems to be making the assumption that I know what all the desired values are.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有运行代码,但是让我知道它是否不起作用,祝你好运
I didn't get to run the code but let me know if it didn't work, good luck