[英]How can I select just one column from a data frame in R that meets certain condition
I am new to R and I am doing some exercises but I do not get the expected output.我是 R 的新手,我正在做一些练习,但我没有得到预期的 output。 I created a data frame with 4 columns.我创建了一个包含 4 列的数据框。 ab,c,d I want to see in my output column c when column d only has values ( B and C) only. ab,c,d 我想在我的 output 列 c 中看到只有值(B 和 C)。
The way I am doing is subset(DFAsg1, b == "B" | y == "C")我正在做的方式是子集(DFAsg1,b ==“B”| y ==“C”)
this returns all the columns in the data frame, but I want to select only column c.这将返回数据框中的所有列,但我只想 select 列 c。
subset(DFAsg1, b == "B" | y == "C", select = "c")
We could do我们可以做
if(all(DFAsg1$d %in% c("B", "C"), na.rm = TRUE)) DFAsg1['c']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.