[R] Why does R do this?

Nick Wray nichol@@@wr@y @ending from ntlworld@com
Tue Jan 8 10:28:44 CET 2019


y<-c(1,2,3)
z<-which(y>3)
z
y<-y[-z]
y

In the work I'm doing I often have this situation and have to make sure that I condition on z being non-zero as y is now numeric(0) rather than the set c(1,2,3).  Why does R do this?  Wouldn't it be more sensible for R to simply leave the host set unchanged if there are no elements to take out?

Any thoughts?

Thanks, Nick Wray
	[[alternative HTML version deleted]]



More information about the R-help mailing list