【问题标题】:Reshaping the current dataframe into another dataframe and creating new columns (concatenate)将当前数据框重塑为另一个数据框并创建新列(连接)
【发布时间】:2019-09-12 15:49:32
【问题描述】:

我有附加的数据框 (here),我需要将其重塑为如下所示的格式

基本上,我想将每个比较每个 traet 组(LA、RA、BiA)添加到 NP 治疗组,并创建一个在 Studlab 和治疗臂之间连接的列。

我尝试使用我之前回答的问题 (here) 来解决这个问题,但我做不到。 任何建议将不胜感激。

【问题讨论】:

  • 查看reshape
  • 到目前为止你有什么尝试?
  • 感谢您的跟进。我读了 reshape 包,但还没有弄清楚。所以我在excel中手动完成,这很耗时。任何意见将不胜感激。

标签: r reshape


【解决方案1】:

如果没有数据样本并且不知道 2Total 和 Group2.event 的确切来源,很难为您提供帮助。但基础应该是这样的:

df %>% 
 gather(treat2:treat4, key = "key", value = "tmp_compare_groupe") %>% 
 mutate(Compare_Groups = paste0("NP_", tmp_compare_groupe), 
        2nd.Total = case_when(tmp_compare_groupe == "LA" ~ LA,
                              tmp_compare_groupe == "RA" ~ RA,
                              tmp_compare_groupe == "BIA" ~ BIA,
                               ))

我不知道 Group2.event 来自哪里。计算完所有列后,您必须选择所需的列。

【讨论】:

  • 感谢您提供此代码。数据框已作为超链接附加在帖子的第一行。欣赏。
猜你喜欢
  • 2019-04-16
  • 2020-05-27
  • 1970-01-01
  • 1970-01-01
  • 2018-02-13
  • 1970-01-01
  • 1970-01-01
  • 2021-01-19
  • 1970-01-01
相关资源
最近更新 更多