[R] VectorComparison

2010-10-18 Thread Paolo Agnolucci
Hi all,

I am not exactly fluent in R and I got stuck with this. I would like to
compare each elements of a vector A with any of the elements in Vector B.
For some reasons it does not work.

 StartDate = as.Date(01/10/2007, %d/%m/%Y)
 TimeSpan = seq(StartDate, by = 'days', length =
length(myAverageCWVs$X1986))

 TickLabels = c(2007-10-01,  2007-11-01,  2007-12-01,  2008-01-01)

 TimeSpan[1:40] == TickLabels
Here I would expect TRUE for teh first entry and then TRUE for the entry
related to 2007-11-01. This doesn't seem to be the case.

 [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[37] FALSE FALSE FALSE FALSE


Thanks you in advance for any help.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] VectorComparison

2010-10-18 Thread Joshua Wiley
Hi,

You might consider ?match  For example:

StartDate = as.Date(01/10/2007, %d/%m/%Y)
TimeSpan = seq(StartDate, by = 'days', length = 40)
TickLabels = as.Date(c(2007-10-01,  2007-11-01,  2007-12-01,
2008-01-01), %Y-%m-%d)

TimeSpan[1:40] == TickLabels  # not designed for comparing multiple
values on each side
TickLabels %in% TimeSpan[1:40] # Find which TickLabels are in TimeSpane
TimeSpan[1:40] %in% TickLabels # Find which TimeSpane are in TickLabels


HTH,

Josh

On Mon, Oct 18, 2010 at 5:50 AM, Paolo Agnolucci
agnolucp...@googlemail.com wrote:
 Hi all,

 I am not exactly fluent in R and I got stuck with this. I would like to
 compare each elements of a vector A with any of the elements in Vector B.
 For some reasons it does not work.

 StartDate = as.Date(01/10/2007, %d/%m/%Y)
 TimeSpan = seq(StartDate, by = 'days', length =
 length(myAverageCWVs$X1986))

 TickLabels = c(2007-10-01,  2007-11-01,  2007-12-01,  2008-01-01)

 TimeSpan[1:40] == TickLabels
 Here I would expect TRUE for teh first entry and then TRUE for the entry
 related to 2007-11-01. This doesn't seem to be the case.

  [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [37] FALSE FALSE FALSE FALSE


 Thanks you in advance for any help.

        [[alternative HTML version deleted]]

 __
 R-help@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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@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.


Re: [R] VectorComparison

2010-10-18 Thread Henrique Dallazuanna
Use %in% instead of '=='

On Mon, Oct 18, 2010 at 10:50 AM, Paolo Agnolucci 
agnolucp...@googlemail.com wrote:

 Hi all,

 I am not exactly fluent in R and I got stuck with this. I would like to
 compare each elements of a vector A with any of the elements in Vector B.
 For some reasons it does not work.

  StartDate = as.Date(01/10/2007, %d/%m/%Y)
  TimeSpan = seq(StartDate, by = 'days', length =
 length(myAverageCWVs$X1986))

  TickLabels = c(2007-10-01,  2007-11-01,  2007-12-01,  2008-01-01)

  TimeSpan[1:40] == TickLabels
 Here I would expect TRUE for teh first entry and then TRUE for the entry
 related to 2007-11-01. This doesn't seem to be the case.

  [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE
 [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE
 [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE
 [37] FALSE FALSE FALSE FALSE


 Thanks you in advance for any help.

[[alternative HTML version deleted]]

 __
 R-help@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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] VectorComparison

2010-10-18 Thread Paolo Agnolucci
Yes - that worked. Thank you. Incidentally I was also comparing a date to a
string which surely didn't help

Thanks again

Ron




On Mon, Oct 18, 2010 at 2:01 PM, Henrique Dallazuanna www...@gmail.comwrote:

 Use %in% instead of '=='

   On Mon, Oct 18, 2010 at 10:50 AM, Paolo Agnolucci 
 agnolucp...@googlemail.com wrote:

  Hi all,

 I am not exactly fluent in R and I got stuck with this. I would like to
 compare each elements of a vector A with any of the elements in Vector B.
 For some reasons it does not work.

  StartDate = as.Date(01/10/2007, %d/%m/%Y)
  TimeSpan = seq(StartDate, by = 'days', length =
 length(myAverageCWVs$X1986))

  TickLabels = c(2007-10-01,  2007-11-01,  2007-12-01,
  2008-01-01)

  TimeSpan[1:40] == TickLabels
 Here I would expect TRUE for teh first entry and then TRUE for the entry
 related to 2007-11-01. This doesn't seem to be the case.

  [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE
 [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE
 [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE
 [37] FALSE FALSE FALSE FALSE


 Thanks you in advance for any help.

[[alternative HTML version deleted]]

 __
 R-help@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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O


[[alternative HTML version deleted]]

__
R-help@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.