[R] dataframes of unequal size

From: Renuka Sane <renukas_at_gmail.com>
Date: Mon 18 Jul 2005 - 19:38:05 EST


I have two dataframes C and C1. Each has three columns viz. state, psu and weight. The dataframes are of unequal size i.e. C1 could be 2/25/50 rows and C has 42000 rows. C1 is the master table i.e. C1$state, C1$psu and C1$weight are never the same. ThisA. P., Urban, 0 is not so for C.

For example
C
state, psu,weight
A. P., Urban, 0

Mah., Rural, 0
W.B., Rural,0
Ass., Rural,0
M. P., Urban,0

A. P., Urban, 0
...

C1

state, psu, weight
A. P., Urban, 1.3
A. P., Rural, 1.2
M. P., Urban, 0.8

......

For every row of C, I want to check if C$state==C1$state and C$psu==C1$psu. If it is, I want C$weight <- C1$weight, else C$weight should be zero.

I am doing the following
for( i in 1:length(C$weight)) {
 C$w[C$state[i]==C1$state & C$psu[i]==C1$psu] <- C1$w[C$state[i] == C1$state & C$psu[i] == C1$psu]
}

This gives me the correct replacements for the number of rows in C1 and then just repeats the same weights for the remaning rows in C.

Can someone point out the error in what I am doing or show the correct way of doing this?

Thanks,
Renuka



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 18 19:44:23 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:46 EST