我有一个连续变量Total_testscore
。我将其分为4组,但它们的样本量不相等。如何拆分变量,以使变量的结果级别具有相同的样本量?
> mydata$Total_testscore_f <- cut(mydata$Total_testscore, breaks = 4)
> table(mydata$Total_testscore_f)
(1.99,5.5] (5.5,9] (9,12.5] (12.5,16]
25 116 95 50
答案 0 :(得分:0)
您可以使用quantile()
函数来获取所需的休息时间。示例:
> x <- rnorm(100) # replace with your real data
> table(cut(x, breaks = quantile(x, seq(0, 1, l=5)), include.lowest = TRUE))
[-2.07,-0.756] (-0.756,0.0664] (0.0664,0.963] (0.963,2.83]
25 25 25 25