Hello I have been looking for a solution for quite some time. I'm sure the answer is easy but I've been pulling my hair out here!
I have two data frames that are similar (in fact one represents a more complete dataset). They both have two columns, one containing string values as a factor and one containing numerical values.
df.A looks like this:
Category Number
A 1
B 2
C 3
D 4
and df.B looks like this
Category Number
A 5
B 6
C 7
These categories (ABCD) are common between the two dataframes. In trying to get df.B to have a category D with a NA or 0 value (I am working with percentages so either NA or 0 is fine), my code looks like this:
proto <- df.A
proto$number <- NULL
df.B <- rbind.fill(proto,df.B)
My thought is this would add the fourth row for category D and give NA value but instead results in
Category Number
A NA
B NA
C NA
D NA
NA 5
NA 6
NA 7
I tried removing the factor class from category on both df.A and df.B, tried using rbind.fill.matrix instead...to be honest I am pretty new to R and this is giving me a lot of trouble. How do I get R to recognize that ABCD are the same factor across dataframes?