0

I have a dataframe:

ID   Name     Value
1    John      44
1              44
2    Mike      235
3    Fred      32
4    Lena      11
4    Lena     

I want to keep only those rows with full columns. So desired result is:

ID   Name     Value
1    John      44
2    Mike      235
3    Fred      32
4    Lena      11
french_fries
  • 1,149
  • 6
  • 22

1 Answers1

0

You can compare the data with empty values and select only those rows where no empty values are present . Using rowSums this can be done as :

df[rowSums(df == "") == 0 , ]
#  ID Name Value
#1  1 John    44
#3  2 Mike   235
#4  3 Fred    32
#5  4 Lena    11

Another option is to turn the empty values to NA and use na.omit to remove such rows.

df[df == ''] <- NA
na.omit(df)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213