How do I select empty cells from column D1 of my database (image attached)
I tried as follows:
df<-read_excel('C:/Users/Antonio/Desktop/test.xlsx')
x<-subset(df,df$D1=="")
But it did not work.
How do I select empty cells from column D1 of my database (image attached)
I tried as follows:
df<-read_excel('C:/Users/Antonio/Desktop/test.xlsx')
x<-subset(df,df$D1=="")
But it did not work.
We could use complete_cases
from base R:
To select empty rows:
df
x <- subset(df, !complete.cases(df))
Output:
D1 D2 D3 A1 A2 A3
2 <NA> s r 1 5 3
4 <NA> as 3 2 4 5
7 <NA> da r 3 6 3
OR
To select non empty rows:
x <- subset(df, complete.cases(df))
Output:
D1 D2 D3 A1 A2 A3
1 a f a 0 2 4
3 b da d 12 3 5
5 c ad f 4 6 7
6 d da d 3 5 6
Maybe it was read as NA
, then use is.na
to detect the NA elements
subset(df, is.na(D1))
Or if there are whitespaces, i.e. " "
, use trimws
to remove those and use ==
subset(df, trimws(D1) == "")
Or if it is both (just to generalize), then do a |
condition
subset(df, is.na(D1)|trimws(D1) == "")