[R] subset syntax

Jens Nieschulze jniesch at gwdg.de
Mon Aug 13 17:09:55 CEST 2001


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")
> 
> 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
> 

hmm lets have a look at the manual

Description

Binary operators which allow the comparison of values in vectors.
[snip]
x == y
x != y

Value

A vector of logicals indicating the result of the element by element
comparison. The elements of shorter vectors are recycled as necessary. 

#***********************
so length(xx$LOCAL.NAME) is uneven in your example, I assume; furthermore
c("Chifumbata","Chikota") as a two element vector is recycled to match
xx$LOCAL.NAME
and
c("Chifumbata","Chifumbata","Chikota","Chifumbata")==c("Chifumbata","Chikota") 
[1]  TRUE FALSE FALSE FALSE
so ...==c("Chifumbata","Chikota") would only find "Chikota" when it is an
entry with an even row number

I assume
subset(xx,LOCAL.NAME=="Chifumbata" | LOCAL.NAME=="Mososo",whatever-column)
 should do what you want

	J

***********************************************************************
Jens Nieschulze

Institute for Forest Biometrics 	Phone: ++49-551-39-12107
37077 Goettingen		E-mail: jniesch at uni-forst.gwdg.de
GERMANY				http://www.uni-forst.gwdg.de/~jniesch

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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