0
我已經設法用下面的代碼創建了列「qaurtile」,但是我還想創建一個名爲「quartile_team」的列來顯示每個團隊內的四分位數。我無法弄清楚如何做到這一點。R:如何在組內創建一個四分位數列
幫助表示讚賞,
保羅
# generate dataset
teams <- c(rep("East", 6), rep("West", 8), rep("North", 7), rep("South", 9))
time_spent <- rnorm(30)
dataset <- as.data.frame(cbind(teams, time_spent))
dataset$time_spent <- as.numeric(dataset$time_spent)
# create quartile column
dataset <- within(dataset,
quartile <- cut(x = time_spent,
breaks = quantile(time_spent, probs = seq(0, 1, 0.25)),
labels = FALSE,
include.lowest = TRUE))