I Have a Dataframe that is Mean Tables by PSPP. I would like to reshape it in order to manipulate it easier for plots in calc.
What I want to do?
- This Table contains descriptive statistics such as Mean, SD, N.
- The levels of Categorical variables are populated vertically.
V1 V1_levelA, V1_levelB, | V2 V2_levelA, V2_levelB ... etc. - Descriptive statistics are vertically displayed
I would like the first variable to be populated horizontally, and the next one vertically. Please see, the attached image for more information.
The result must take into consideration that Table may missing entire factor levels - cause they may have not "values", and therefore not included in the input table in the form of csv.
I hope this huge editing be clearer now what I am asking.
Dput sample df similar to that of the posted image:
df <- structure(list(structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L,
1L, 1L, 1L, 1L, 1L, 1L), .Label = c("", "v1", "v2"), class = "factor"),
varA = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L,
2L, 3L, 3L, 4L, 4L), .Label = c("k1", "k2", "k3", "k4", "varA"
), class = "factor"), Age = structure(c(1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L), .Label = c("a1",
"a2", "Age"), class = "factor"), Mean = structure(1:15, .Label = c("10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "21",
"22", "23", "24", "25", "Mean"), class = "factor"), N = structure(c(1L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 2L, 3L, 4L, 5L, 6L,
7L), .Label = c("1", "10", "12", "13", "14", "15", "16",
"2", "3", "4", "5", "6", "7", "8", "9", "N"), class = "factor")), row.names = 2:16, class = "data.frame")
*Update**
Check that:
My input and the desired Output:
https://postimg.cc/N2GTZd09