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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With