I am trying to do logistic reasoning in R. Suppose I have columns from A to I (A,B,C,D,E,F,G,H,I). Now I want to assign Z to data frame which has columns A,B,C,D,G,H. How will I do the same in R?
            Asked
            
        
        
            Active
            
        
            Viewed 87 times
        
    0
            
            
        - 
                    You can do `df1[c(1:4, 6:7)]` – akrun May 03 '19 at 17:14
- 
                    Combine them how? Are these 2 data frames that you want to join, or column-bind, or some other operation? Try to build a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that we can help with more specifically, because right now it's pretty unclear what exactly you're working with. – camille May 03 '19 at 17:33
1 Answers
2
            
            
        We can use numeric indexing to select the columns
df1[c(1:4, 6:7)]
If we need two datasets, use setdiff to select column names that we don't need 
df2 <- df1["A"]
df3 <- df1[setdiff(names(df1), "A")]
 
    
    
        akrun
        
- 874,273
- 37
- 540
- 662
- 
                    Is there any way, that if I need to assign df2 to data frame having column A and another data frame (say df3) containing rest of the columns? – shrutya m May 03 '19 at 17:20
