[R] subset syntax

Winfried Theis theis at statistik.uni-dortmund.de
Mon Aug 13 18:28:14 CEST 2001


Hi Mikkel!
On Mon, 13 Aug 2001, Grum, Mikkel wrote:

> Can anyone tell me what's wrong with this command??
> 
> xx<-subset(x,LOCAL.NAME==c("Chifumbata","Chikota"),select=c(13,16,19,23,26,2
> 9,30,33:48))
> 
> Warning message: 
> longer object length
>         is not a multiple of shorter object length in: LOCAL.NAME ==
> c("Chifumbata", "Chikota")
I suppose you want to extract all elements of x where LOCAL.NAME matches
Chifumbata or Chikota. The operation == does an elementwise comparison of
the elements of two vectors. The operation you want here would be
"%in%" which compares every element in LOCAL.NAME with all elements in the
list c("Chifumbata", "Chikota") and if it finds a match gives true. 

so try:

xx<-subset(x,LOCAL.NAME %in% c("Chifumbata","Chikota"),select=c(13,16,19,23,26,2
 9,30,33:48))

Cheers,

Winfried 
> 
> both of the following commands work fine
> xx<-subset(x,LOCAL.NAME==c("Chikota"),select=c(13,16,19,23,26,29,30,33:48))
> xx<-subset(x,LOCAL.NAME==c("Chifumbata"),select=c(13,16,19,23,26,29,30,33:48
> ))
> 
> but I want a file with both the Chifumbatas and the Chikotas and several
> others.
> 
> Cheers,
> Mikkel
> 
> 
> 
> Mikkel Grum
> Genetic Diversity Scientist
> International Plant Genetic Resources Institute (IPGRI)
> Sub-Saharan Africa Group
> ***
> m.grum at cgiar.org
> ipgri-kenya at cgiar.org
> www.ipgri.cgiar.org
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

________________________________________________________________________
Dipl.-Math. Winfried Theis			   Tel:++49 231/755-5903
SFB 475, FB Statistik, Universit"at Dortmund, 44221 Dortmund
e-mail: theis at amadeus.statistik.uni-dortmund.de


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list