I have 2 dataset
data1=structure(list(x1 = c(7L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L), x2 = c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L), x3 = c(1L, 1L, 1L, 2L, 1L, 2L,
1L, 1L, 2L), x4 = c(156L, 156L, 238L, 156L, 238L, 238L, 156L,
156L, 156L), x5 = c(0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L), x5.1 = c(31L,
1L, 9L, 8L, 6L, 11L, 3L, 3L, 2L), x6 = structure(c(1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L), .Label = c("En", "RU"), class = "factor"),
x7 = structure(c(2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L), .Label = c("13",
"other"), class = "factor"), x8 = c(1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 1L), x9 = c(0L, 1L, 0L, 0L, 2L, 3L, 2L, 0L, 0L),
x10 = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L), x11 = c(745L,
120L, 140L, 200L, 130L, 410L, 460L, 460L, 675L), x12 = c(440L,
120L, 140L, 200L, 130L, 410L, 460L, 460L, 445L), x13 = c(2L,
0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L), prediction = structure(c(1L,
5L, 6L, 8L, 7L, 2L, 3L, 3L, 4L), .Label = c("0.0646", "0.0713",
"0.1319", "0.2629", "0.3479", "0.3693", "0.4037", "0.4123"
), class = "factor")), class = "data.frame", row.names = c(NA,
-9L))
and second dataset
data2=structure(list(pred = structure(c(4L, 2L, 1L, 3L, 1L, 5L, 7L,
6L, 6L, 1L), .Label = c("0.0226902365684509", "0.0326902365684509",
"0.0826902365684509", "0.1211001253128052", "0.411001253128052",
"0.611001253128052", "0.64564001253128052"), class = "factor")), class = "data.frame", row.names = c(NA,
-10L))
How for each variable x1-x13
create pivot table with data1$prediction
and data2$pred
aggerated by means
For example desired output for variable x1
x1 mean_prediction mean_pred
7 0.31 0.056
6 0.14 0.569
I.E in output must 12 tables in one dataframe. and not separated data frames. How to do it?
#update
structure(list(x1 = c(7L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L), x2 = c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L), x3 = c(1L, 1L, 1L, 2L, 1L, 2L,
1L, 1L, 2L), x4 = c(156L, 156L, 238L, 156L, 238L, 238L, 156L,
156L, 156L), x5 = c(0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L), x5.1 = c(31L,
1L, 9L, 8L, 6L, 11L, 3L, 3L, 2L), x6 = structure(c(1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L), .Label = c("En", "RU"), class = "factor"),
x7 = structure(c(2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L), .Label = c("13",
"other"), class = "factor"), x8 = c(1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 1L), x9 = c(0L, 1L, 0L, 0L, 2L, 3L, 2L, 0L, 0L),
x10 = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L), x11 = c(745L,
120L, 140L, 200L, 130L, 410L, 460L, 460L, 675L), x12 = c(440L,
120L, 140L, 200L, 130L, 410L, 460L, 460L, 445L), x13 = c(2L,
0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L), prediction = structure(c(1L,
5L, 6L, 8L, 7L, 2L, 3L, 3L, 4L), .Label = c("0.0646", "0.0713",
"0.1319", "0.2629", "0.3479", "0.3693", "0.4037", "0.4123"
), class = "factor"), pred = c(0.121100125, 0.032690237,
0.022690237, 0.082690237, 0.022690237, 0.411001253, 0.645640013,
0.611001253, 0.611001253)), class = "data.frame", row.names = c(NA,
-9L))