给定一个数据框列,它是一系列整数(年龄),我想将整数范围转换为序数变量。
我当前的代码不起作用,我该怎么做?
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)