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
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
%in% worked wonders. Thanks a lot! Mikkel -----Original Message----- From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk] Sent: 13 August 2001 19:15 To: Jens Nieschulze Cc: Grum, Mikkel; R-help at stat.math.ethz.ch Subject: Re: [R] subset syntax Jens Nieschulze <jniesch at gwdg.de> writes:> I assume > subset(xx,LOCAL.NAME=="Chifumbata" | LOCAL.NAME=="Mososo",whatever-column) > should do what you wantThe %in% operator is also handy in these cases: subset(xx, LOCAL.NAME %in% c("Chifumbata", "Mososo"), ....) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._