R-员工报告结构 [英] R - Employee Reporting Structure

查看:74
本文介绍了R-员工报告结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我正在使用R和一些软件包从票务系统中提取JSON数据。我要吸引所有用户,并希望建立报告结构。

Background: I am using R along with some packages to pull JSON data from a ticketing system. I'm pulling all the users and want to build a reporting structure.

我有一个包含员工及其经理的数据集。这些列是这样命名的(雇员和经理)。我正在尝试构建一棵到根的报告结构树。我们在一个IT组织中,但是我要提取所有员工数据,所以看起来像是这样:

I have a data set that contains employees and their managers. The columns are named as such ("Employee" and "Manager"). I am trying to build a tree of a reporting structure that goes up to the root. We are in an IT organization, but I am pulling all employee data, so this would look something like:

公司->业务部门->行政人员->董事->小组经理->经理->雇员

Company -> Business Unit -> Executive -> Director -> Group Manager -> Manager -> Employee

这是基本概念。有些区域的树形结构很小,而另一些区域则是多层的。基本上,我想做的是得到一棵树或我可以引用的报告结构,以便为某位员工确定其董事是谁。可以删除1个级别,也可以删除最多5个或6个级别。

That's the basic idea. Some areas have a tree structure that is small, others it's multiple levels. Basically, what I am trying to do is get a tree, or reporting structure I can reference, so I can determine for an employee, who their director is. This could be 1 level removed or up to 5 or 6 levels removed.

我遇到了 data.tree ,但到目前为止,我必须提供一个 pathString 定义了该结构。由于我只有两列,因此我想做的就是将此数据帧放入函数中,并在找到员工时遍历列表,将其放在该经理下,当它找到该经理作为员工时,将其与嵌套在其下的所有内容一起嵌套在其直接报告下。

I came across data.tree, but so far, as I look at it, I have to provide a pathString that defines that structure. Since I only have the two columns, what I'd like to do is throw this data frame into a function and have it traverse the list as it finds the employee, put it under that manager, when it finds that manager as an employee, nest it under their direct report, along with anything nested under them.

我无法弄清楚如何使 data.tree 这样做而不定义 pathString ,但是这样做只能根据我对每一行(员工及其经理)的了解来构建 pathString 。结果是一棵只有2个级别的树,董事未连接到其组经理,组经理未连接到其经理,依此类推。

I haven't been able to figure out how to make data.tree do this without defining the pathString, but in doing so, I can only build the pathString on what I know for each row - the employee and their manager. The result is a tree that only has 2 levels and directors aren't connected to their Group Manager and Group Managers aren't connected to their managers and so forth.

我曾考虑编写一些逻辑/循环来完成此操作,但是必须有一种更简单的方法或可以用来执行此操作的程序包。也许我没有正确定义 pathString ...。

I thought about writing some logic/loops to go through and do this, but there must be an easier way or a package that I can use to do this. Maybe I am not defining the pathString correctly....

最终,我想要的是最终结果将成为具有以下列的数据框:

Ultimately, what I'd like the end result to be is a data frame with columns that look like:

Employee,Manager1,Manager2,Manager3,ManagerX等...

Employee, Manager1, Manager2, Manager3, ManagerX, ...

当然,某些行只会在第1列和第2列中有条目,但其他一些行可能会上升许多级别。了解这些信息后,就可以在我们的配置管理系统中查找设备,找到所有者并将这些计数汇总到适当的主管下。

Of course some rows will only have entries in columns 1 and 2, but others could go up many levels. Once I have this, I can look up devices in our configuration management system, find the owner and aggregate those counts under the appropriate director.

任何帮助将不胜感激。我无法发布数据,因为它本质上是机密的,但仅包含员工及其经理。我只需要连接所有点...谢谢!

Any help would be appreciate. I cannot post the data, as it is confidential in nature, but it simply contains the employee and their managers. I just need to connect all the dots... Thanks!

推荐答案

data.tree包中的 FromDataFrameNetwork 函数仅适用于这种情况:

The data.tree package has the FromDataFrameNetwork function for just this scenario:

library(data.tree)

DataForTree <- data.frame(manager = c("CEO","sally","sally","sue","mary", "mary"),
                          employee = c("sally","sue","paul","mary","greg", "don"),
                          stringsAsFactors = FALSE)


tree <- FromDataFrameNetwork(DataForTree)

print(tree)

结果为:

1 CEO                 
2  °--sally           
3      ¦--sue         
4      ¦   °--mary    
5      ¦       ¦--greg
6      ¦       °--don 
7      °--paul  

这篇关于R-员工报告结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆