How to bind matrix to a dataframe so that matrix remains only ONE variable?

Dear community,

I have 1 dataframe:

> str(fail)
'data.frame':	99 obs. of  2 variables:
 $ Gender: Factor w/ 3 levels "w","m","x": 1 1 2 1 2 2 1 2 2 1 ...
 $ Sksum : int  23 28 26 38 30 21 29 39 32 29 ...

And one matrix containing data:

> str(Interest)
 num [1:99, 1:33] 3 2 5 4 1 1 3 1 4 3 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:33] "Item011" "Item012" "Item013" "Item021" ...

I would like to bind them so that I have 3 variables: Interest, Gender and SKsum.
It should look like this model data in the end:

> str(VerbalAggression)
'data.frame':	316 obs. of  3 variables:
 $ resp  : num [1:316, 1:24] 0 0 1 1 1 2 2 0 0 2 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:24] "S1WantCurse" "S1DoCurse" "S1WantScold" "S1DoScold" ...
 $ gender: Factor w/ 2 levels "female","male": 2 2 1 1 1 1 1 1 1 1 ...
 $ anger : int  20 11 17 21 17 21 39 21 24 16 ...

while anger=Sksum (from fail-dataframe), gender=Gender (from fail-dataframe), resp=Interest (from Interest-matrix).

Do you have an idea how I could do that?

THANK YOU VERY MUCH for any suggestions!!!

You should be able to do this using $. So your code would be:

fail$Interest <- Interest
2 Likes

Thanks for your reply. It worked - This is so amazing! :slight_smile: You made my day!!! :smiley: THANK YOU!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.