[R] Error 0ps.factor: level sets of factors are different

lind35 lindb at vcu.edu
Thu Nov 29 03:42:32 CET 2012


I have two data sets: "new" and "combo". Within both data set, each row
pertains to a unique individual. The "combo" data set is a subset of the
"new" data set, meaning that all individuals within "combo" are within "new"
but not all individuals within "new" are within "combo". Thus, nrow(new) >
nrow(combo). 

Each data set has particular columns that represent the same sort of measure
(i.e., height, individual ID). However, the "new" data set does not have the
height values. Moreover, some of the height values within "combo" are blank.
I want R to identify a unique individual between data sets and then put the
individual's height from the "combo" data set into the "new" data set. I
would like to do this in a for-loop, but I keep getting errors.

"ID" columns are new[,17] and combo[,11]
"height" columns are new[,14] and combo[,6]

for example I try:
> for (i in 1:nrow(new)) {
+ temp <- combo[which(new[i,17] == combo[,11]),6]
+ if(length(temp) == 0) {new[i,14] <- NA
+ } else{new[i,14] <- combo[which(new[i,17] == combo[,11]),6]}
+ }

I can see how combo[,11] isn't the same as the new[i,17]. How do I tell R to
look at the ID value for the i'th row within "new", search the 11th column
of "combo" until it finds the matching ID, then place the height from that
individual from "combo" into the appropriate cell of "new"? And on top of
this, do this over and over until it's transferred all of the heights from
"combo" to the appropriate individuals in "new"?

Thanks for the help!



--
View this message in context: http://r.789695.n4.nabble.com/Error-0ps-factor-level-sets-of-factors-are-different-tp4651246.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list