[R] conditional with and operators
Steven McKinney
smckinney at bccrc.ca
Tue Aug 19 22:33:45 CEST 2008
Did you try it with the vector '&' and operator?
d<-sapply(res,function(.df){(.df$TimesVisited[.df$Tick>912 & .df$Id>0])})
(The '&&' operator is designed for use in
e.g. if() clauses where you want a scalar logical
answer)
HTH
Steve McKinney
-----Original Message-----
From: r-help-bounces at r-project.org on behalf of Altaweel, Mark R.
Sent: Tue 8/19/2008 1:10 PM
To: r-help at r-project.org
Subject: [R] conditional with and operators
Hi,
I have a problem in which I am parsing data from a list. I am simply trying to return data that has several conditions being true. Here is my syntax below:
d<-sapply(res,function(.df){(.df$TimesVisited[.df$Tick>912 && .df$Id>0])}) #res is the list, and I am trying to return a result that has two true conditions (that is the variable Tick should be greate than 912 and Id should be greater than 0
This returns an array of 10 with integer values of 0. This is the incorrect result
However, if I do the same syntax except I remove the && statement (i.e. the second conditional), then the result producing something that makes sense, which is all values that are Tick and greater than 912.
Can someone let me know how I can setup my data to be parsed so I can have 2 or multiple conditionals in my function that is looking at an array.
Thanks in advance.
Mark
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list