I'm trying to combine two datasets, based on a condition. This would make it easier for me to analyze if all variables would be in 1 dataset. Both datasets have information in the form of variables (columns) as well as an Identifier variable (also a column). This Identifier variable is present in both datasets. Based on this Identifier variable, I want to copy all the specifc information in the cells from one dataset to another. I've already tried to work with a for loop, an if-then-else function and the mutate-funtion.
Below is an example script, the identifier is ''review.id'', the desired result can be found at the bottom. I have basic experience in R, but combining multiple datasets is new for me.
review.id <- c(1, 2, 3)
car <- c('Audi','Volkswagen','Skoda')
house.value <- c(143000, 187000, 223000)
df1 <- data.frame(review.id,car,house.value)
View(df1)
review.id <- c(3, 1, 2)
city <- c('Berlin','Sydney','Rio')
kids <- c(3, 0, 1)
df2 <- data.frame(review.id,city,kids)
View(df2)
#Desired Result (df3)
#review.id car house.value city kids
#1 Audi 143000 Sydney 0
#2 Volkswagen 187000 Rio 1
#3 Skoda 223000 Berlin 3
Thanks in advance! :)
Aucun commentaire:
Enregistrer un commentaire