Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.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中按列添加数据帧子集中的所有记录?_R_Dataframe - Fatal编程技术网

如何在R中按列添加数据帧子集中的所有记录?

如何在R中按列添加数据帧子集中的所有记录?,r,dataframe,R,Dataframe,如何在数据帧中保留所有未使用的列的同时,获得test1到test57行中所有列的值之和 它将仅使用数值对所有行求和 Participant ID Test1 Test2 Test3 Test4 Test5 Test6 Test7 ... Test57 ParticipantA asd 2 4 2 3 2 3 4 7 ParticipantB sxa 1 3 2 2

如何在数据帧中保留所有未使用的列的同时,获得test1到test57行中所有列的值之和

它将仅使用数值对所有行求和

  Participant   ID   Test1 Test2 Test3 Test4 Test5 Test6 Test7 ... Test57
  ParticipantA  asd    2      4    2     3      2      3   4           7  
  ParticipantB  sxa    1      3    2     2      3      3   3           8
  ParticipantC  agff   1      4    4     2      3      4   2           9
  ParticipantD  asx    2      4    2     3      2      4   4           4
  ParticipantE  axp    3      2    2     2      2      2   3          96

df$Sum使用
rowSums
df$Sum <- rowSums(df[sapply(df, is.numeric)], na.rm = TRUE)