How to combine two dataframes in the correct order using R

Asked

Viewed 99 times

1

df <- read.csv('train.csv')  
train1 <- train[train$variavel3 == 1]  
train2 <- train[train$variavel3 == 0]  
fit1 <- rpart(variavel1~variavel2)  
fit2 <- rpart(variavel1~variavel2)  
dftest <- read.csv('test.csv')  
dftest1 <- test[test$variavel3 == 1]  
dftest2 <- test[test$variavel3 == 0]  
prediction1 <- predict(fit1, dftest1)  
prediction2 <- predict(fit2, dftest2)   

dataframe1-----------dataframe2
x1---x2-----------------x1------x2
1----0-------------------2-------0
3----0-------------------4-------1
6----1-------------------5-------1

I want to join the dataframes so that X1 is in the correct order

  • 2

    Hello Pedro, welcome to Stack Overflow. Could you edit your question and specify what you mean by "join"? It would just create a dataframe with the data from prediction1 followed by data from prediction2?

  • It would not be just join, as for example use rbind, because it has to be in the order of a variable. I just discovered the function merge. I’ll test you now

  • The idea of merge was good but did not work, saying "no data available in table"

  • You may be looking for this: http://answall.com/q/124319/6036

  • I improved my question

1 answer

1

I got the answer.
I joined the two data frames with a rbind()
and then I used a arrange() to sort the way I wanted. Thank you so much for all your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.