Hello,
I seperated one data frame into two data frames and calculated "f1" and "f2" for both data frames seperately.
head(data1)
ID light lux time rdom f1 f2
1 11 26 19 12 2.1 34
4 11 26 19 12 22.9 31
6 11 26 19 12 6.6 7
head(data2)
ID light lux time rdom f1 f2
2 11 26 19 12 2.8 24
3 11 26 19 12 24.3 34
5 11 26 19 12 9.2 5
No I want to merge the dataframes back together so that there is a data set with all ID´s in it. I want to keep the columns "light", "lux", "time" & "rdom" only once, as they are the same in both dataframes. Also I want to sort the data by the ID. So basically I want the final data frame to look like that:
ID light lux time rdom f1 f2
1 11 26 19 12 2.1 34
2 11 26 19 12 2.8 24
3 11 26 19 12 24.3 34
4 11 26 19 12 22.9 31
5 11 26 19 12 9.2 5
6 11 26 19 12 6.6 7
In order to do so I used the function merge():
Data.final <- merge(data1, select(data2, -light, -lux, -time, -rdom), by = "ID", all.x=TRUE)
Following data set results:
ID light lux time rdom f1.x f2.x f1.y f2.y
1 11 26 19 12 2.1 34 NA NA
2 11 26 19 12 NA NA 2.8 24
3 11 26 19 12 NA NA 24.3 34
4 11 26 19 12 22.9 31 NA NA
5 11 26 19 12 NA NA 9.2 5
6 11 26 19 12 6.6 7 NA NA
Is there a way to avoid those extra columns (.x, .y) and NAs?
edit: Sorry for the relocated columns. I sadly don´t know how to fix that..
Thank you so much in advance!