Skip to content
Prev 79407 / 398503 Next

creating a derived variable in a data frame

A shorter alternative to the above is to use %in% like:

mydata$continent[ mydata$country %in% c("US","CA","MX") ] <- "NoAm"

You could also create a new data frame with 2 columns for the country
and 
corresponding continent, then merge this with your data (see ?merge).
Greg Snow, Ph.D.
Statistical Data Center, LDS Hospital
Intermountain Health Care
greg.snow at ihc.com
(801) 408-8111