Dear Sir,
 
Thanks a lot for your solution and guidance. It worked wonderfully.
 
Regards
 
Maithili

--- On Thu, 27/8/09, Gabor Grothendieck <ggrothendi...@gmail.com> wrote:


From: Gabor Grothendieck <ggrothendi...@gmail.com>
Subject: Re: [R] Fw: PROBLEM - - COMPARING AND COMBINING two DATASETS
To: "Maithili Shiva" <maithili_sh...@yahoo.com>
Cc: r-help@r-project.org
Date: Thursday, 27 August, 2009, 2:09 PM


Try this:

xtabs(B ~ factor(A, seq(max(A))))


On Thu, Aug 27, 2009 at 8:26 AM, Maithili Shiva<maithili_sh...@yahoo.com> wrote:
>
>
>
>
>
>
>
> Dear Sirs,
>
> At the outset I sincerely apologize for reproducing my query to you. I also 
> thank all of you for the solution you had provided. It has worked on the 
> actual data I am working with.
>
> However, there is this peculiar problem which I had realized only after I had 
> obtained my results.
>
> e.g. in the example I had attached
>
> A <- c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31)
> B <- c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, 
> .0033,0..2282, 0.1614)
>
> tapply( B, A, sum)
>
> I get R output as –
>
>  1          2          3            7     
>        14          31
> 4.3938   1.0266   2.6770    2.7875    0.0033    0.1614
>
> However, my requirement is I should get the output as
>
> 1          2          3         4  5  6  7   
>       8  9 …. 14 ………..31
> 4.3938 1.0266  2.6770   0  0  0  2.7875  0  0 ..0.0033 .. 0.161
>
> i.e. my output should include the values 4, 5, 6, etc. which are not part of 
> dataset A and the corresponding totals in B (which are anyways 0’s). I need 
> this for my further analysis. Its possible for me to add these 0’s 
> manually, however when the dataset is large, its not practical.
>
> I am attaching herewith an excel file. I will be grateful if you can guide me.
>
> Thanks in advance
>
> Maithili
> start: 2009-08-18 end: 0000-00-00
>
> Thinking of ordering food? Find restaurant numbers on Yahoo! India Local
>
>
>      Love Cricket? Check out live scores, photos, video highlights and 
> more. Click here http://cricket.yahoo.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.
>
>



      Love Cricket? Check out live scores, photos, video highlights and more. 
Click here http://cricket.yahoo.com
        [[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.

Reply via email to