R:如果另一个列中的行缺少值,则如何在另一列的列中提取值名和另一列的列名

发布于 2025-02-10 11:42:22 字数 1842 浏览 1 评论 0原文

我不确定该如何言语,或者是否可能会说,但是目标是从第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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2025-02-17 11:42:22
soybean %>% pivot_longer(-Class, names_to = "with_na" , values_to ="values") %>% filter(is.na(values)) %>% select (Class, with_na)

我没有运行代码,但是让我知道它是否不起作用,祝你好运

soybean %>% pivot_longer(-Class, names_to = "with_na" , values_to ="values") %>% filter(is.na(values)) %>% select (Class, with_na)

I didn't get to run the code but let me know if it didn't work, good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文