Hi! I want to know if a given element <- ('c64') is part of a vector<- ('c64', 'amiga', 'atari'). Does a function exist for this which gives back a logical value? thankx db
"Dominik Bach" <dominik.bach at directbox.com> writes:> Hi! > > I want to know if a given element <- ('c64') is part of a vector<- ('c64', 'amiga', 'atari'). > > Does a function exist for this which gives back a logical value?> 'c64' %in% c('c64', 'amiga', 'atari')[1] TRUE -- 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
?"%in%" ?is.element On Wed, 6 Oct 2004, Dominik Bach wrote:> I want to know if a given element <- ('c64') is part of a vector<- > ('c64', 'amiga', 'atari'). > > Does a function exist for this which gives back a logical value?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Wed, 2004-10-06 at 11:23, Dominik Bach wrote:> Hi! > > I want to know if a given element <- ('c64') is part of a vector<- > ('c64', 'amiga', 'atari'). > > Does a function exist for this which gives back a logical value? > > thankx > db> v <- c("c64", "amiga", "atari", "MITS Altair", "pong")> "c64" %in% v[1] TRUE Also, for the position in the vector, you can use:> which(v == "c64")[1] 1 See ?"%in%" and ?which for more information. HTH, Marc Schwartz
Try element %in% vector or look at match() -roger Dominik Bach wrote:> Hi! > > I want to know if a given element <- ('c64') is part of a vector<- ('c64', 'amiga', 'atari'). > > Does a function exist for this which gives back a logical value? > > thankx > db > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >