[R] replacing then summing by values from another dataframe

Xianming Wei XWei at sugarresearch.com.au
Tue Aug 11 03:05:05 CEST 2015


[I might have sent  the following request to a wrong email address - 'r-help-request at r-project.org']

Hi,



I have two data frame dat1 and dat2.



dat1 <- data.frame(pid = paste('C', 1:5, sep = ''),

                                    m1 = c(2, 2, 1, -1, 0),

                                     m2 = c(1, 0, 1, -1, 1),

                                     m3 = c(0, 1, 1, -1, 0))

dat2 <- data.frame(mid = paste('m', 1:3, sep = ''),

                                    '0' = c(-19.5482, -.512, -.492),

                                     '1' = c(.007, 3.241, -2.256),

                                     '2' =c(1.223, -4.490, 1.779)) names(dat2)[-1] <- c('0', '1', '2')



dat1 contains individuals with scores of three measurements (-1 represents missing) and dat2 with the effect of the different levels of the three measurements. What I'd like to do is to summise the effects of three measurements based on the level effects. So C1 I want to get the values of dat2 for m1 at level 2 = 1.223, m2 at level 1 = 3.241 and m3 at level 0 = -0.4920 and sum them up as 3.972.



I can only think of a loop to do that at the moment. Because of much higher dimensions of actual two datasets, I need help to come up with an efficient / elegant approach.



Any help is much appreciated.





Regards,

Xianming



Regards,
Xianming


-------------------- Internet e-Mail Disclaimer -------------------- 

PRIVILEGED - PRIVATE AND CONFIDENTIAL: This email and any files transmitted with it are intended solely for the use of the addressee(s) and may contain information, which is confidential or privileged. If you are not the intended recipient, be aware that any disclosure, copying, distribution, or use of the contents of this information is prohibited. In such case, you should destroy this message and kindly notify the sender by reply e-mail. The views and opinions expressed in this e-mail are those of the sender and do not necessarily reflect the views of the company. 

VIRUSES:  Email transmission cannot be guaranteed to be secure or error free, as information may be intercepted, corrupted, lost, destroyed, arrive late or incomplete or contain viruses. This email and any files attached to it have been checked with virus detection software before transmission. You should nonetheless carry out your own virus check before opening any attachment. Sugar Research Australia Limited does not represent or warrant that files attached to this email are free from computer viruses or other defects and accepts no liability for any loss or damage that may be caused by software viruses

	[[alternative HTML version deleted]]



More information about the R-help mailing list