I'm trying to merge/bind two datasets (mydata_103 and mydata_17). They have exactly the same variable names, however I get 4 of these warning messages
Warning messages:
1: In `[<-.factor`(`*tmp*`, ri, value = c(1, 1, 2, 1, 1, 1, 1, 1, 5, :
invalid factor level, NA generated
This seems to be caused by the fact that some variables have different classes. For example, I have a variable "gender" (1 = male, 2 = female). In the merged dataset, I do see value labels for mydata_17, however for the other dataset I get NA's. When I checked the classes, R returned they are different (I don't know why this is the case though?)
> lapply(mydata_103[7], class)
$prgesl
[1] "numeric"
> lapply(mydata_17[7], class)
$prgesl
[1] "factor"
I changed the class of mydata_103 to factor
mydata_103$prgesl <- as.factor(mydata_103$prgesl)
Now, I do get the numeric values, but it still doesn't translate to the value labels:
prgesl
15 Man
16 Man
17 Vrouw
18 2
19 2
20 1
21 2
Does anyone know how to fix this? And is there a way to get the classes for my two datasets the same or check which ones differ? (I have 404 variables so to check this by visual inspection seems ineffecient and prone to errors).
Best, Hanneke
Edit: The code to merge my datasets right now is simply:
data1 <- rbind.data.frame(mydata_17, mydata_103)