Re: [R] Data length mismatch.

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat, 26 Jul 2008 18:28:22 -0400

Sorry, the last one should be:

ix <- match(B$DayOfYear, A$DayOfYear)
A[ix, "x"] <- A[ix, "x"] - B$x

Again we are assuming B's days are a subset of A's.

On Sat, Jul 26, 2008 at 6:08 PM, Gabor Grothendieck <ggrothendieck_at_gmail.com> wrote:
> Here is a third solution.
>
> A[B$DayOfYear, "x"] <- A[B$DayOfYear, "x"] - B$x
>
> Its assumes B's days are a subset of A's but if that's not the case then
> you would need to intersect them first: ?intersect
>
> On Sat, Jul 26, 2008 at 5:26 PM, <rkevinburton_at_charter.net> wrote:
>> I have two vectos (list) that represent a years of data. Each "row" is represented by the day of year and the quantity that was sold for that day. I would like to form a new vector that is the difference between the two years of data. A sample of A (and similarly B) looks like:
>>
>>> A[1:5,]
>> DayOfYear x
>> 1 1 1429
>> 2 2 3952
>> 3 3 3049
>> 4 4 2844
>> 5 5 2219
>>>
>>
>> D <- A - B
>>
>> This works just fine if A and B are both the same length. How is the best way to handle the situation where A and B are of different lengths? If the day of year exists in both vectors (lists) then I just want the coorespondng "row" in D to be the difference btween A and B values. If the "row" doesn't exist in either A or B then the difference should be treated as if the missing "row" was zero. Is this feasible?
>>
>> Thank you.
>>
>> Kevin
>>
>> ______________________________________________
>> 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.
>>
>



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. Received on Sat 26 Jul 2008 - 22:33:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Jul 2008 - 23:32:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive