Skip to content
Prev 321469 / 398500 Next

group data

Hello,

Try the following.


dat <- read.table(text = "
ID  Value
AL1  1
AL2  2
CA1  3
CA4  4
", header = TRUE, stringsAsFactors = FALSE)

dat$State <- substr(dat$ID, 1, 2)


Note that this dependes on having State being defined by the first two 
characters of ID.

Hope this helps,

Rui Barradas


Em 11-04-2013 19:37, Ye Lin escreveu: