rbind()返回矩阵而不是数据帧,arrange()不安排时间

时间:2019-01-11 20:01:55

标签: r rbind

我想合并两个具有相同列数但不同行数的数据集,并希望根据ID,DATE和TIME进行排列。

> head(df2_1)
  C        ID DV    DATE      TIME   TSFD  TSLD  DOSE   MDV  EVID  RATE DUR      WT   AGE HEIGHT BMI         SEX    AMT     aDUR
  <fct> <int> <fct> <fct>     <fct> <dbl> <dbl> <int> <int> <int> <dbl> <fct> <dbl> <dbl> <fct>  <fct>       <fct>  <fct>  <dbl>
1 ""    11003 .     3/14/2007 22:00     0     0    75     1     1  246. .      54.7  44.6 73     15.89851181 Female 245.97     1
2 ""    11003 .     3/14/2007 23:00     1     0    75     1     1  246. .      54.7  44.6 73     15.89851181 Female 245.97     2
3 ""    11003 .     3/15/2007 1:00      3     0    75     1     1  246. .      54.7  44.6 73     15.89851181 Female 245.97     1
4 ""    11003 .     3/15/2007 2:00      4     0    75     1     1  246. .      54.7  44.6 73     15.89851181 Female 245.97     1
5 ""    11003 .     3/15/2007 3:00      5     0    75     1     1  246. .      54.7  44.6 73     15.89851181 Female 245.97     1
6 ""    11003 .     3/15/2007 4:00      6     0    75     1     1  246. .      54.7  44.6 73     15.89851181 Female 245.97     2
> head(df2_2)
  C    ID       DV      DATE  TIME     TSFD        TSLD DOSE MDV EVID RATE DUR     WT      AGE HEIGHT         BMI    SEX AMT aDUR
1   11003 2315.688 3/16/2007 14:05 40.08333  0.08333333    0   0    0    0   .  54.66 44.60233     73 15.89851181 Female   .    .
2   11003 1651.839 3/17/2007  8:45 58.75000  0.75000000    0   0    0    0   .  54.66 44.60233     73 15.89851181 Female   .    .
3   11010  768.886 4/23/2007  9:38 21.13333  1.63333333    0   0    0    0   . 122.70 49.79877     62  49.4759054 Female   .    .
4   11010 437.5375 4/24/2007  9:15 44.75000  0.25000000    0   0    0    0   . 122.70 49.79877     62  49.4759054 Female   .    .
5   11010 489.4601 4/25/2007  9:51 69.35000 22.85000000    0   0    0    0   . 122.70 49.79877     62  49.4759054 Female   .    .
6   11021 202.3625 6/10/2007 11:00 42.08333 39.00000000    0   0    0    0   .  60.00 40.56126     69 19.53375047 Female   .    .

我尝试了df2 <- rbind(df2_1,df2_2)。这将返回一个较大的矩阵,而不是数据帧。

然后我使用df2 <- rbind.data.frame(df2_1,df2_2)确实返回一个数据帧。但是,当我想根据ID,DATE和TIME df2 <- rbind.data.frame(df2_1,df2_2)%>%group_by(ID)%>%arrange(ID,DATE,TIME)安排数据帧时。安排功能在TIME无效。时间从1:00到10:00,然后到2:00。

感谢您的投入!

0 个答案:

没有答案