jeudi 17 décembre 2015

Removing NA from Column based on Condition in R

I have a dataframe where based on the condition of two of the columns, I want to remove the rows with NA's from a different column.

I tried this but it doesn't seem to be working:

removerows<-ifelse(df$MONTH==12 & 
df$YEAR==2015,
df[complete.cases(df$Retlisher),],
df[!complete.cases(df$Retlisher),])

When I try this, R crashes. This is the original dataframe:

  Place1234   We_source Wevisetiser   MONTH YEAR Weater.Size Revenue QP.TERuests Opportunities PaTP.WQpreOPIons
1                             <NA> MTD: 12 2015       LARGE       0      219768             0                0
2            abcdefghij abcdefghij      12 2015     UNKNOWN       0           0             2                0
3            abcdefghij abcdefghij MTD: 12 2015     UNKNOWN       0           0             2                0
4           1ek4nd2 (4)    1ek4nd2      12 2015     UNKNOWN       0           0             0                0
5                             <NA>      12 2015       LARGE       0      219768             0                0
6            abcdefghij abcdefghij      12 2015     UNKNOWN       0           0             2                0
  Weep Amount Weep.Rate Overall.Weep.Rate WALS.Rate RET OPT Retlisher Placement.Type Platform.Type Geography
1    0      0         0                 0         0   0   0      <NA>           <NA>          <NA>      <NA>
2    0      0         0                 0         0   0   0      <NA>           <NA>          <NA>      <NA>
3    0      0         0                 0         0   0   0      <NA>           <NA>          <NA>      <NA>
4    0      0         0                 0         0   0   0      <NA>           <NA>          <NA>      <NA>
5    0      0         0                 0         0   0   0      <NA>           <NA>          <NA>      <NA>
6    0      0         0                 0         0   0   0      <NA>           <NA>          <NA>      <NA>
  Type1
1  <NA>
2  <NA>
3  <NA>
4  <NA>
5  <NA>
6  <NA>

Aucun commentaire:

Enregistrer un commentaire