My data is composed by a list of dfs: 268 dfs contained in z the name of the list
Each df has the following str
df <- structure(list(id = structure(c(50109025, 60901029, 140103026,
50705001, 110113007, 111201026, 50521001, 111201007, 60901030,
50508026, 50508026, 110113003, 110113008, 111202009, 140103023,
50203026, 110113005, 140102088, 110104030, 140102095), label = "Identificador", format.spss = "F10.0", display_width = 10L),
name = c("ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1",
"ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1",
"ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1", "ABCA1"
), `1` = c(1.063, 1.623, 1.078, 1.765, 1.596, 0.365, 0.53,
0.672, 1.77, 0.875, 0.875, 1.426, 0.569, 0.921, 0.988, 1.017,
1.208, 0.642, 0.703, 0.834), `3` = c(0.753, 2.05, 2.132,
1.961, 1.165, 0.764, 1.983, 1.59, 1.028, 1.488, 1.488, 2.226,
1.16, 0.967, 0.95, 1.761, 1.488, 0.871, 5.634, 0.898)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -20L))
# This dfs came from splitted df according to the variable **name**
My idea is to iterate through the 268 dfs, each one with differente name, and perform paired t.test between the columns 1 and 3, with the id column as grouped variable
#1st approach
names <- names(z)
rowvars <- c(names)
rowvars <- base::sort(rowvars)
for (v in 1:length(rowvars)) {
P1 <- t.test(x= z[,v[3]][, "1"], y= z[,v[4]][, "3"], paired = TRUE)$p.value
}
# 2nd approach
lapply(z, function(x){t.test(x = z[[x]][, "1"], y = z[[x]][, "3"], paired = TRUE)
})
# purrr approach
I have tried purrr drafts but enough consistent to post them
All I am getting is errors: "Enough observations of x"
Thank in advance