我有以下数据,其中:
PseudoID = ID,Trim_SSW = 妊娠三个月(1、2 或 3),体重= SSW 时间点的受试者体重,SSW = 孕周
structure(list(PseudoID = c(1001L, 1001L, 1001L, 1001L, 1001L,
1001L, 1001L, 1001L, 1001L, 1001L, 1001L, 1001L, 1001L, 1002L,
1002L, 1002L, 1002L, 1002L, 1002L, 1002L), Trim_SSW = c("T1",
"T1", "T2", "T2", "T2", "T3", "T3", "T3", "T3", "T3", "T3", "T3",
"T3", "T1", "T1", "T1", "T2", "T2", "T2", "T3"), weight = c(120.8,
120.9, 120.8, 122.2, 122.5, 125, 124.6, 126.6, 126.4, 126.7,
126.7, 128, 129.3, 101.7, 100.5, 100.2, 101.7, 104.2, 104.2,
105.6), SSW = c(8L, 12L, 15L, 19L, 23L, 27L, 30L, 33L, 35L, 36L,
37L, 38L, 39L, 9L, 10L, 13L, 18L, 22L, 25L, 29L)), .Names = c("PseudoID",
"Trim_SSW", "weight", "SSW"), row.names = c(4L, 5L, 15L, 12L,
17L, 16L, 11L, 6L, 3L, 1L, 2L, 18L, 20L, 46L, 47L, 49L, 42L,
43L, 48L, 31L), class = "data.frame")
对于每个 ID,我想查看每个三个月的体重增加情况。因此,我需要分别在 T1、T2 和 T3 中找到最后一次测量和第一次测量之间的差异。在三个月内只有 1 次测量可用的情况下,我想输入 NA。我假设制作 3 个新变量(T1gain、T2gain、T3gain)会简化进一步的计算。
我在这里看到了类似的帖子,但它没有完全回答我的问题,我被要求发一个新帖子。