I have trouble finding the right code for the following problem:
My data table has multiple columns representing different variables representing repeated measurements. I would like to summarize the repeated measurements in R
library(data.table)
data.table(structure(list(exp = c("480 p36", "480 p36", "480 p36", "480 p36",
"480 p36", "480 p36"), well = c("A", "A", "A", "A", "A", "A"),
col = c("001", "002", "003", "004", "005", "006"), `T peak` = c(1.63,
1.67, 1.56, 1.47, 1.59, 1.55), `T rise` = c(0.2, 0.18, 0.18,
0.13, 0.14, 0.17), `T fall` = c(0.13, 0.16, 0.16, 0.15, 0.23,
0.2), TCT = c(0.86, 0.77, 0.73, 0.76, 0.71, 0.62), `D peak` = c(0.02,
0.02, 0.02, 0.02, 0.01, 0.01), `D valley` = c(0, 0, 0, 0,
0, 0), `D high` = c(0.01, 0.02, 0.02, 0.02, 0.01, 0.01),
`D low` = c(0, 0, 0, 0, 0, 0), AUC = c(0.01, 0.01, 0.01,
0.01, 0, 0), Power = c(0.01, 0.01, 0.01, 0.01, 0, 0), CR = c(0.1,
0.12, 0.16, 0.14, 0.07, 0.05), RR = c(-0.1, -0.11, -0.11,
-0.12, -0.04, -0.04)), row.names = c(NA, -6L), class = "data.frame"))
In a first step I grouped the table with
group <- group_by(output, col)
I made a variable vector:
variables <- colnames(group[,4:15], do.NULL = TRUE)
I would like to summarize each variable grouped by column col
and column
exp
. Tried to summarize the data like mean, SEM, and count.
it works with
summarize(group, mTCT = mean(`TCT`, na.rm = TRUE), SEM_TCT = sd(`TCT`,na.rm=TRUE)/sqrt(n()), nTCT=n())
But I thought it would be better to replace every single column name with the variable vector. But that doesn't work.
Any advice?
question from:
https://stackoverflow.com/questions/65873995/repeat-group-analysis-on-multiple-columns-in-r