0

I have the following three datasets:

CoverageData1:

Class    Coverage
Eval     0.6
Reader   0.96
Eval     0.2
Queue    0.33
Reader   0.5
Reader   0.28
Queue    0.66

CoverageData2:

Class    Coverage
Queue    0.61
Eval     0.02
Eval     0.9
Reader   0.48
Eval     0.99

I want to combine them in one dataframe like:

Class   Coverage1   Coverage2
Eval    0.6     0.02
Eval    0.2     0.9
Eval            0.99
Reader  0.96        0.48        
Reader  0.5
Reader  0.28
Queue   0.33        0.61
Queue   0.66

For this, I did the following:

new_data <- data.frame()
for(class in classes){
  c1 <- CoverageData1$Coverage[CoverageData1$Class == class]
  c2 <- CoverageData2$Coverage[CoverageData2$Class == class]
  new_data <- cbind(new_data,c1)
  new_data <- cbind(new_data,c2)
}

When I run this, I get nothing. I see that data in c1 and c2 but they are not combined in new_data. Do you know how to solve it?

Adam Amin
  • 1,406
  • 2
  • 11
  • 23

1 Answers1

1

You could try

merge(CoverageData1, CoverageData2, by="Class", all.x=TRUE, all.y=TRUE)

see ?merge for details


EDIT: You could actually just try new_data <- cbind(c1,c2) because you are now trying to cbind NULL value with some data.

gaut
  • 5,771
  • 1
  • 14
  • 45