简体   繁体   English

我怎样才能 select 仅从 R 中满足特定条件的数据框中的一列

[英]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.

相关问题 如何选择满足特定条件的R数据帧中的第一行? - How do I select the first row in an R data frame that meets certain criteria? 如何根据R中data.frame中相应列的满足条件显示列 - How to display a column based on a condition that meets true for corresponding column in data.frame in R 如何根据另一列是否满足 R 中的条件为列分配字符值? - How can I assign a column a character Value based on whether another column meets a condition in R? 如何使用selectInput从R中的数据框中选择特定列? - How can I select a specific column from a data frame in R using selectInput? 我如何滞后满足其他列(R)中条件的先前值? - How can i LAG the previous value that meets a condition in other column (R)? 在 R 中,我如何 select 来自一个数据帧的所有变量在另一个数据帧中? - In R, how do I select all variables from one data frame that are in another data frame? 是否有更好的方法来找到满足R中数据帧另一列中每个值的条件的一列的百分比? - Is there a better way to find the percent of one column that meets a criteria for each value in another column for a data frame in R? 仅将R中的一列重命名数据框中的列名 - rename column name in data frame by just one column in R 如果至少有一个组成员满足条件,则从 data.frame 中删除组 - Remove group from data.frame if at least one group member meets condition 如果至少一个组成员满足条件,则将组保留在数据框中 - Keep group in data frame if at least one group member meets condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM