本文介绍了从基线改变重复的ID,缺少基线点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从基线更改重复的ID,缺少基线点

Change from baseline for repeated ids with missing baseline points

下面已经提出并回答了类似的问题:

A similar question has been asked and answered below:

我的问题与原来的问题不同在于我缺少基准值。我在下面包含一个很小的可重复的例子:

My question differs from the original question in that I have missing baseline values. I am including a small reproducible example below:

df1 <- data.frame( probeID = c( rep("A", 19), rep("B",19), rep("C",19)),
                   Subject_ID = c( rep( c( rep(1,5), rep(2,4), rep(3,5), rep(4,5)),3)),
                   time = c(rep( c( c(1:5), c(2:5), rep( 1:5,2)),3)))
df1$measure <- df1$Subject_ID*c( 1:nrow(df1))

df2 <- subset( df1, Subject_ID != 2)

df2 %>%
  group_by(probeID, Subject_ID) %>%
  mutate(change = measure - measure[time==1])

但是,当我在上面的管道中替换df2时,它失败,因为时间= 1的数据丢失Subject_ID = 2的数据点。在df1中我想要的输出应该与df2的输出相同。我会感谢任何帮助。

However, when I replace df2 with df1 in the pipe above, it fails because data is missing for the time = 1 data point for Subject_ID=2. My desired output in the df1 case should be be identical to the output from df2. I would appreciate any help.

感谢

JJ

推荐答案

有一些麻烦,想弄清楚你的问题是要求的,这是否有效?

Was having some trouble trying to figure out what your question was asking for, does this work?

df1 %>%
  group_by(probeID, Subject_ID) %>%
  mutate(change = measure - first(measure))

这篇关于从基线改变重复的ID,缺少基线点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 19:20