I am confused about the conditional if statement in R.
What I want:
Let's say there are two variables; Data$Export & Data$Sales,
Only if both Data$Export & Data$Sales for a row has the value '0', I want the row to be removed from the dataset. Or, as I thought, to set any variable in the row to NA, which will consequently be removed with: "Data <- na.omit(Data) " anyway.
Therefore, I thought of the following construction:
for (i in 1:nrow(Data)) { if ( (Data$Sales[i] == 0) &(Data$Export[i] == 0 ) ) {Data$Sales [i] <- NA }} Data <- na.omit(Data)
However, this does not work, the error code yields: missing value where TRUE/FALSE needed
Thank you in advance for any help I may receive.
Kind regards, Anouk
Aucun commentaire:
Enregistrer un commentaire