Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在r中的三列数据帧中制作from、to网络_R - Fatal编程技术网

在r中的三列数据帧中制作from、to网络

在r中的三列数据帧中制作from、to网络,r,R,我希望每个人都做得很好,我有问题在一篇文章中创建一个维基百科文章的编辑网络(当一篇文章完成后开始另一篇文章网络)。该网络将在以后用于查找用户和文章的程度中心。数据框看起来像 faID uName time_Stamp 1 Qaless 2003-09-06T20:27:00Z 1 Austin 2003-10-31

我希望每个人都做得很好,我有问题在一篇文章中创建一个维基百科文章的编辑网络(当一篇文章完成后开始另一篇文章网络)。该网络将在以后用于查找用户和文章的程度中心。数据框看起来像

faID           uName                     time_Stamp
 1               Qaless                 2003-09-06T20:27:00Z
 1               Austin                 2003-10-31T06:07:03Z
 1               SimonP                 2004-02-10T19:15:56Z
 1               SimonP                 2004-02-10T19:23:44Z
 1             Moncrief                2004-02-10T19:28:09Z
 1             Moncrief                2004-02-10T19:28:48Z
 1                  Rbs                2004-02-10T20:21:35Z
 1            Camembert                2004-02-10T20:27:34Z
 2             Moncrief                2004-02-10T20:29:33Z
 2                  Rbs                2004-02-10T20:39:33Z
 2              Jason M                2004-05-18T23:54:15Z
 2             Rickyrab                2004-05-28T05:35:32Z
 2             Rickyrab                2004-05-28T05:37:10Z
 2              Postdlf                2004-06-08T03:26:25Z
 2              Modster               2004-08-10T17:22:37Z
 3            PhilHibbs               2004-08-23T14:09:54Z
 3             Sfoskett               2004-09-10T18:22:15Z
 3               Dalton               2004-09-12T17:34:13Z
 3               Dalton               2004-09-12T17:38:35Z
 3      Ta bu shi da yu               2004-09-17T07:24:10Z
faid      to         from        time stamp 
 1         Qaless    Qaless        2003-09-06T20:27:00Z
 1        Qaless     Austin        2003-10-31T06:07:03Z
 1        Austin     SimonP        2004-02-10T19:15:56Z
 1        SimonP     SimonP        2004-02-10T19:23:44Z
 1        SimonP     Moncrief      2004-02-10T19:28:09Z
 1        Moncrief   Moncrief      2004-02-10T19:28:48Z
 1        Moncrief     Rbs         2004-02-10T20:21:35Z
 1        Camembert    Rbs         2004-02-10T20:27:34Z
 2        Moncrief   Moncrief      2004-02-10T20:29:33Z
 2        Moncrief    Rbs          2004-02-10T20:39:33Z
 2        Rbs        Jason M       2004-05-18T23:54:15Z
 2        jason M    Rickyrab     2004-05-28T05:35:32Z
 2        Rickyrab  Rickyrab      2004-05-28T05:37:10Z
 2        Rickyrab     Postdlf    2004-06-08T03:26:25Z
 2        Postdlf    modster      2004-08-10T17:22:37Z
 3        PhilHibbs PhilHibbs     2004-08-23T14:09:54Z
 3        PhilHibbs Sfoskett      2004-09-10T18:22:15Z 
 3        Sfoskett  Dalton        2004-09-12T17:34:13Z
 3        Dalton    Dalton        2004-09-12T17:38:35Z 
 3    dalton     Ta bu shi da yu  2004-09-17T07:24:10Z
我想要一个网络数据框,它看起来像

faID           uName                     time_Stamp
 1               Qaless                 2003-09-06T20:27:00Z
 1               Austin                 2003-10-31T06:07:03Z
 1               SimonP                 2004-02-10T19:15:56Z
 1               SimonP                 2004-02-10T19:23:44Z
 1             Moncrief                2004-02-10T19:28:09Z
 1             Moncrief                2004-02-10T19:28:48Z
 1                  Rbs                2004-02-10T20:21:35Z
 1            Camembert                2004-02-10T20:27:34Z
 2             Moncrief                2004-02-10T20:29:33Z
 2                  Rbs                2004-02-10T20:39:33Z
 2              Jason M                2004-05-18T23:54:15Z
 2             Rickyrab                2004-05-28T05:35:32Z
 2             Rickyrab                2004-05-28T05:37:10Z
 2              Postdlf                2004-06-08T03:26:25Z
 2              Modster               2004-08-10T17:22:37Z
 3            PhilHibbs               2004-08-23T14:09:54Z
 3             Sfoskett               2004-09-10T18:22:15Z
 3               Dalton               2004-09-12T17:34:13Z
 3               Dalton               2004-09-12T17:38:35Z
 3      Ta bu shi da yu               2004-09-17T07:24:10Z
faid      to         from        time stamp 
 1         Qaless    Qaless        2003-09-06T20:27:00Z
 1        Qaless     Austin        2003-10-31T06:07:03Z
 1        Austin     SimonP        2004-02-10T19:15:56Z
 1        SimonP     SimonP        2004-02-10T19:23:44Z
 1        SimonP     Moncrief      2004-02-10T19:28:09Z
 1        Moncrief   Moncrief      2004-02-10T19:28:48Z
 1        Moncrief     Rbs         2004-02-10T20:21:35Z
 1        Camembert    Rbs         2004-02-10T20:27:34Z
 2        Moncrief   Moncrief      2004-02-10T20:29:33Z
 2        Moncrief    Rbs          2004-02-10T20:39:33Z
 2        Rbs        Jason M       2004-05-18T23:54:15Z
 2        jason M    Rickyrab     2004-05-28T05:35:32Z
 2        Rickyrab  Rickyrab      2004-05-28T05:37:10Z
 2        Rickyrab     Postdlf    2004-06-08T03:26:25Z
 2        Postdlf    modster      2004-08-10T17:22:37Z
 3        PhilHibbs PhilHibbs     2004-08-23T14:09:54Z
 3        PhilHibbs Sfoskett      2004-09-10T18:22:15Z 
 3        Sfoskett  Dalton        2004-09-12T17:34:13Z
 3        Dalton    Dalton        2004-09-12T17:38:35Z 
 3    dalton     Ta bu shi da yu  2004-09-17T07:24:10Z
一般解释如下: 至-->人员编辑(即在下一个人员(行下方)之前进行编辑) 从-->人员编辑(位于先前编辑的人员下方)
如果
df
是您的原始
data.frame
,您可以执行以下操作:

transform(df, 
             from = uName, 
             to = ave(as.character(uName), faID, FUN = function(x) c(x[1L], head(x,-1L))), 
             uName = NULL
           )

#    faID           time_Stamp            from        to
# 1     1 2003-09-06T20:27:00Z          Qaless    Qaless
# 2     1 2003-10-31T06:07:03Z          Austin    Qaless
# 3     1 2004-02-10T19:15:56Z          SimonP    Austin
# 4     1 2004-02-10T19:23:44Z          SimonP    SimonP
# 5     1 2004-02-10T19:28:09Z        Moncrief    SimonP
# 6     1 2004-02-10T19:28:48Z        Moncrief  Moncrief
# 7     1 2004-02-10T20:21:35Z             Rbs  Moncrief
# 8     1 2004-02-10T20:27:34Z       Camembert       Rbs
# 9     2 2004-02-10T20:29:33Z        Moncrief  Moncrief
# 10    2 2004-02-10T20:39:33Z             Rbs  Moncrief
# 11    2 2004-05-18T23:54:15Z         Jason M       Rbs
# 12    2 2004-05-28T05:35:32Z        Rickyrab   Jason M
# 13    2 2004-05-28T05:37:10Z        Rickyrab  Rickyrab
# 14    2 2004-06-08T03:26:25Z         Postdlf  Rickyrab
# 15    2 2004-08-10T17:22:37Z         Modster   Postdlf
# 16    3 2004-08-23T14:09:54Z       PhilHibbs PhilHibbs
# 17    3 2004-09-10T18:22:15Z        Sfoskett PhilHibbs
# 18    3 2004-09-12T17:34:13Z          Dalton  Sfoskett
# 19    3 2004-09-12T17:38:35Z          Dalton    Dalton
# 20    3 2004-09-17T07:24:10Z Ta bu shi da yu    Dalton

这里有一个可能的
data.table
解决方案,使用最新的
data.table
版本

library(data.table) # v 1.9.6+
setDT(df)[, to := shift(uName, fill = uName[1L]), by = faID]
setnames(df, "uName", "from")
df
#     faID            from           time_Stamp        to
#  1:    1          Qaless 2003-09-06T20:27:00Z    Qaless
#  2:    1          Austin 2003-10-31T06:07:03Z    Qaless
#  3:    1          SimonP 2004-02-10T19:15:56Z    Austin
#  4:    1          SimonP 2004-02-10T19:23:44Z    SimonP
#  5:    1        Moncrief 2004-02-10T19:28:09Z    SimonP
#  6:    1        Moncrief 2004-02-10T19:28:48Z  Moncrief
#  7:    1             Rbs 2004-02-10T20:21:35Z  Moncrief
#  8:    1       Camembert 2004-02-10T20:27:34Z       Rbs
#  9:    2        Moncrief 2004-02-10T20:29:33Z  Moncrief
# 10:    2             Rbs 2004-02-10T20:39:33Z  Moncrief
# 11:    2         Jason M 2004-05-18T23:54:15Z       Rbs
# 12:    2        Rickyrab 2004-05-28T05:35:32Z   Jason M
# 13:    2        Rickyrab 2004-05-28T05:37:10Z  Rickyrab
# 14:    2         Postdlf 2004-06-08T03:26:25Z  Rickyrab
# 15:    2         Modster 2004-08-10T17:22:37Z   Postdlf
# 16:    3       PhilHibbs 2004-08-23T14:09:54Z PhilHibbs
# 17:    3        Sfoskett 2004-09-10T18:22:15Z PhilHibbs
# 18:    3          Dalton 2004-09-12T17:34:13Z  Sfoskett
# 19:    3          Dalton 2004-09-12T17:38:35Z    Dalton
# 20:    3 Ta bu shi da yu 2004-09-17T07:24:10Z    Dalton

它给了我一个错误,比如
[.data.table
(setDT(na2),
:=
(to,shift(uName,fill=uName[1L]),:找不到函数“shift”是的,我提到你需要开发版本。你是否运行了
库(devtools);安装了github(“Rdatatable/data.table”,build\u vignettes=FALSE)
如我所示的第一步?是的,我安装了库(devtools),但错误是相同的,但您是否运行了
库(devtools);安装了github(“Rdatatable/data.table”,build\u vignettes=FALSE)
安装
devtools
库后?此外,您还需要运行
库(data.table)
之后再试一次。因此它不起作用。请尝试关闭所有R会话。只打开一个会话。然后运行
库(devtools);安装\u github(“Rdatatable/data.table”,build\u vignettes=FALSE)
并查看是否仍有错误。