-2

An example of the data frame I have is:

Index  TimeDifference
1        
2         
3            20
4      
5            67

I want to delete all rows that are blank (these are blank and NOT na). Hence the following data frame I want is:

Index     TimeDifference
3               20
5               67

Thanks

Fiona
  • 477
  • 1
  • 9
  • 18
  • 1
    Please make your example reproducible. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jogo Mar 01 '18 at 13:58

2 Answers2

3

Assuming that TimeDifference is a character column:

df <- data.frame(Index=1:5, TimeDifference=c("","","20","","67"))

Then you can use:

df[-which(df$TimeDifference==""),]

or

df[!(df$TimeDifference==""),]

or

df[df$TimeDifference!="",]

which gives:

  Index TimeDifference
3     3             20
5     5             67
DJack
  • 4,850
  • 3
  • 21
  • 45
0
df <- df[as.character(df$TimeDifference)!= "" ,]
Aleh
  • 776
  • 7
  • 11