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
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
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,
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
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%:
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:
6 matches
Mail list logo