I'm using R and I am trying to delete some rows from a data frame based on some constrains. so, if I got
dat <- data.frame(Cs=c("c1","c2","c3","c4","c5","c6"),
R1=sample(c("Y","N"),6,replace=TRUE), R2=sample(c("Y","N"),6,replace=TRUE),
R3=sample(c("Y","N"),6,replace=TRUE), R4=sample(c("Y","N"),6,replace=TRUE),
R5=sample(c("Y","N"),6,replace=TRUE), R6=sample(c("Y","N"),6,replace=TRUE))
I'd like to delete all the rows having a "N" at some given columns such as R1, R3, R4. For one single column, I found this solution: delete row for certain constrains
d <- dat[dat[,"R1"]!="N",]
which works fine. but if I put multiple columns as
d <- dat[dat[,c("R1","R3","R4")]!="N",]
I got lots of extra rows full of NA. So where am I wrong?