As above. The dataframe is a series of integers which are age. I am trying to convert them into ordinal variables. The code is below.
df <- read.table("http://dl.dropbox.com/u/822467/df.csv", header = TRUE, sep = ",")
df[(df >= 0) & (df <= 14)] <- "Age1"
df[(df >= 15) & (df <= 44)] <- "Age2"
df[(df >= 45) & (df <= 64)] <- "Age3"
df[(df > 64)] <- "Age4"
table(df)
As we can see this doesn't work. Can anyone help me propose a better way to do this?
Use
cut
to do this in one step:Once you are satisfied that the
breaks
are correctly specified, you can then also use thelabels
argument to relabel the levels: