Why does R do this?
Hi It is documented behaviour. "An empty index selects all values: this is most often used to replace all the entries but keep the attributes." so I presume that changing it could break huge amount of code. The only workaround could be to check "z" before using it for indexing. e.g.
if(length(z)==0) z <- length(y) + 1 y[-z]
[1] 1 2 3
Cheers Petr
-----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Nick Wray via R- help Sent: Tuesday, January 8, 2019 10:29 AM To: r-help <r-help at r-project.org> Subject: [R] Why does R do this? 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]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner?s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/ D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/