Reputation: 41
mydata$gender <- c("M", "F", "M")
mydata$country <- c("USA", "USA", "USA")
Create a new variable by combining gender and country. Variable will state "M USA".
So I can't figure out how to combine these 2 categorical data to produce what I want.
I assume that recoding them would take to long.
Is there a way to do this without using the interaction function?
Thanks in advance.
Upvotes: 4
Views: 15060
Reputation: 61154
Something like this...?
> transform(mydata, newvar=paste(gender, country))
gender country newvar
1 M USA M USA
2 F USA F USA
3 M USA M USA
Upvotes: 7