根据一列中的零值删除R个数据帧行 [英] remove R Dataframe rows based on zero values in one column
本文介绍了根据一列中的零值删除R个数据帧行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个数据框,在两列中带有一组零值。 df
I have this dataframe with a set of zero values along two columns. df
Sl_No No_of_Mails No_of_Responses
1 10 2
2 0 0
3 20 0
4 10 10
5 0 0
6 0 NA
7 10 NA
8 10 0
我想删除 No_of_Mails
等于0的那些行,而不会干扰另一列。
我尝试了以下代码
I want to remove those rows where No_of_Mails
equals zero without disturbing the other column.
I have tried the following code
row_sub = apply(df, 1, function(row) all(row !=0 ))
df[row_sub,]
这将删除所有0值,包括 number_of_responses
列中的一个。我希望该列不受干扰
我也尝试过此
This removes all the 0 values including the one from the number_of_responses
column. I wish to have that column undisturbed
I have also tried this
df[df$No_of_Mails][!(apply(df, 1, function(y) any(y == 0))),].
这将删除所有行,并为我提供一个零行的表。
This deletes all the rows and gives me a table with zero rows.
推荐答案
仅基于 No_of_Mails
中的值对数据框进行子集化列:
Just subset the data frame based on the value in the No_of_Mails
column:
df[df$No_of_Mails != 0, ]
这篇关于根据一列中的零值删除R个数据帧行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文