[R] how to test if a vector contain a value?

2010-08-16 Thread Hyunchul Kim
Hi all, How to convert following simple python script to R if x in a_list: print x OR simply, how to test if a vector contain a value? Thank you in advance, Hyunchul [[alternative HTML version deleted]] __ R-help@r-project.org

Re: [R] how to test if a vector contain a value?

2010-08-16 Thread Ista Zahn
Hi Hyunchul, See ?match -Ista On Mon, Aug 16, 2010 at 1:06 PM, Hyunchul Kim hyunchul.kim@gmail.com wrote: Hi all, How to convert following simple python script to R if x in a_list:    print x OR simply, how to test if a vector contain a value? Thank you in advance, Hyunchul

Re: [R] how to test if a vector contain a value?

2010-08-16 Thread Henrique Dallazuanna
Try this: is.element(2, c(1, 2, 4)) On Mon, Aug 16, 2010 at 10:06 AM, Hyunchul Kim hyunchul.kim@gmail.comwrote: Hi all, How to convert following simple python script to R if x in a_list: print x OR simply, how to test if a vector contain a value? Thank you in advance,

Re: [R] how to test if a vector contain a value?

2010-08-16 Thread Marius 't Hart
mylist = c(1,2,3) if (any(mylist == 3)) { print(3) } [1] 3 On 08/16/2010 03:06 PM, Hyunchul Kim wrote: Hi all, How to convert following simple python script to R if x in a_list: print x OR simply, how to test if a vector contain a value? Thank you in advance, Hyunchul

Re: [R] how to test if a vector contain a value?

2010-08-16 Thread Barry Rowlingson
On Mon, Aug 16, 2010 at 2:06 PM, Hyunchul Kim hyunchul.kim@gmail.com wrote: Hi all, How to convert following simple python script to R if x in a_list:    print x OR simply, how to test if a vector contain a value? if(any(a_list == x)){ print(x) } Or use %in%:

Re: [R] how to test if a vector contain a value?

2010-08-16 Thread Grzesiek
You have a lot of different way a-c(1,2,3,NA,3,4,3) is.na(a) [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE a==2 [1] FALSE TRUE FALSENA FALSE FALSE FALSE Look at here: http://cran.r-project.org/doc/manuals/R-intro.html -- View this message in context: