From my small data.frame (i) below, I wonder how to form the following data.frame of vectors?
# Desired output (2 rows x 6 columns):
data.frame(
mpre1=c(.21,1.61) , sdpre1=c(.28,1.5) , n1 = c(21,21), #group=1,control=F,outcome= 1 & 2
mpre2=c(.12,1.13) , sdpre2=c(.25,.92) , n2 = c(16,16)) #group=2,control=T,outcome= 1 & 2
# mpre1 sdpre1 n1 mpre2 sdpre2 n2
#1 0.21 0.28 21 0.12 0.25 16
#2 1.61 1.50 21 1.13 0.92 16
The index values (for group & outcome) to extract the above vectors from i are given by:
rev(expand.grid(outcome = unique(i$outcome),
group = unique(i$group)))
This is a toy example, a functional BASE R answer is highly appreciated.
i = read.csv("https://raw.githubusercontent.com/rnorouzian/m2/main/g.csv")
# study.name group n mpre sdpre mpos sdpos rev.sign post control outcome
#1 Diab_b 1 21 0.21 0.28 0.22 0.44 TRUE 1 FALSE 1
#2 Diab_b 1 21 0.21 0.28 0.08 0.11 TRUE 2 FALSE 1
#3 Diab_b 1 21 1.61 1.50 0.87 0.82 TRUE 1 FALSE 2
#4 Diab_b 1 21 1.61 1.50 1.97 1.04 TRUE 2 FALSE 2
#5 Diab_b 2 16 0.12 0.25 0.15 9.24 TRUE 1 TRUE 1
#6 Diab_b 2 16 0.12 0.25 0.08 0.11 TRUE 2 TRUE 1
#7 Diab_b 2 16 1.13 0.92 0.62 0.43 TRUE 1 TRUE 2
#8 Diab_b 2 16 1.13 0.92 0.84 0.55 TRUE 2 TRUE 2