所以我正在计算员工流动率.最初看似简单的任务证明有点挑战(对我来说很容易,我是人力资源专业人士).
我可以找到列的计数和总和,但我在计算中使用这些值时遇到问题.我已经尝试过搞乱计数,长度和xtabs功能,但都没有成功.我想我可以将数据分成子集,但我认为这不是这里的方法.
以下是我想要找到的内容
#Running_terminations <-
Run Code Online (Sandbox Code Playgroud)
应该是(第1个月的终止)+(第2个月的终止)...... /月数
#Running_headcount <-
Run Code Online (Sandbox Code Playgroud)
应该是(第1个月的人数)+(第2个月的人数)...... /月数
#Annual_turnover <-
Run Code Online (Sandbox Code Playgroud)
(运行终止/运行人数)*12
As Of Status Gender Type
1/31/2015 Termination Male A
1/31/2015 Active Female A
1/31/2015 Active Male B
1/31/2015 Active Female B
1/31/2015 Active Male A
2/29/2015 Active Female A
2/29/2015 Active Male B
2/29/2015 Active Female B
2/29/2015 New Hire Male A
2/29/2015 Termination Female A
3/31/2015 Active Male B
3/31/2015 Active Female B
3/31/2015 Active Male A
3/31/2015 Termination Female A
3/31/2015 Active Male B
Run Code Online (Sandbox Code Playgroud)
因此,在上面的样本数据中,截至3月(2015年3月31日)的运行营业额将如下所示,
Running_terminations =(1 + 1 + 1)/ 3 = 1
Running_headcount =(4 + 3 + 4)/ 3 = 3.7 注意,只有状态"活动"计入人数
Annual_turnover =(1/3.7)*100 = 27%
一旦我掌握了基础知识,我希望能够按性别,类型或两者的性别和类型计算营业额.
非常感谢你阅读这篇文章.
编辑:
如果有帮助,这就是我在Tableau中进行计算的方法.
Running Terminations (YTD) = zn(WINDOW_AVG((([Termination])),-11,0))
Running Headcount (YTD) = zn(WINDOW_AVG((([Active])),-11,0))
Annual Turnover (YTD) = (ZN(([Running Terminations])/[Running Headcount]))*12
Run Code Online (Sandbox Code Playgroud)
所以我首先计算了年初至今的周转率,然后乘以12.
我做了一些关于计算运行平均值的阅读,我发现这里的用户建议使用以下功能.
ma <- function(x,n=5){filter(x,rep(1/n,n), sides=2)}
Run Code Online (Sandbox Code Playgroud)
现在我想把它应用到我的问题上.
我认为主要的问题是我无法通过"截止日期"对事物进行分类.另一个例子是,我想制作一个双轴图,每月显示终端和新员工,但我只能获得总数并最终绘制点.我怎样才能每月展示一次?
您可以重塑数据以计算每月的活动数量和终止数量。这是代码:
library(reshape2)
txt <- "As.Of Status Gender Type
1/31/2015 Termination Male A
1/31/2015 Active Female A
1/31/2015 Active Male B
1/31/2015 Active Female B
1/31/2015 Active Male A
2/29/2015 Active Female A
2/29/2015 Active Male B
2/29/2015 Active Female B
2/29/2015 New_Hire Male A
2/29/2015 Termination Female A
3/31/2015 Active Male B
3/31/2015 Active Female B
3/31/2015 Active Male A
3/31/2015 Termination Female A
3/31/2015 Active Male B"
dataSet <- read.table(textConnection(txt), header=TRUE)
dataSet$As.Of <- as.Date(dataSet$As.Of, format="%m/%d/%y")
dataSet$As.Of.Month <- format(dataSet$As.Of, "%m")
dataSetAgg <- dcast(dataSet, As.Of.Month ~ Status, fun.aggregate = length, value.var="As.Of.Month")
Running_terminations <- sum(dataSetAgg$Termination)/nrow(dataSetAgg)
Running_headcount <- sum(dataSetAgg$Active)/nrow(dataSetAgg)
Annual_turnover <- (Running_terminations/Running_headcount)*100
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。