Hi ALL,
I have got a following dataframe:
my_temp <- structure(list(DES1 = structure(c(
0, 2, 2, 0, 1, 3, 1, 1, 4,
3
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES2 = structure(c(
2,
1, 3, 2, 1, 2, 1, 4, 1, 3
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES3 = structure(c(
0,
1, 0, 1, 1, 2, 4, 0, 4, 1
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES4 = structure(c(
4,
3, 0, 1, 2, 2, 2, 0, 3, 3
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES5 = structure(c(
3,
1, 2, 4, 2, 2, 4, 4, 4, 4
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES6 = structure(c(
3,
3, 0, 2, 1, 1, 3, 1, 2, 3
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES7 = structure(c(
2,
2, 2, 1, 1, 2, 2, 3, 3, 1
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES8 = structure(c(
0,
1, 0, 0, 0, 0, 1, 0, 1, 1
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES9 = structure(c(
0,
1, 0, 0, 0, 1, 1, 0, 4, 2
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double")), DES10 = structure(c(
4,
1, 2, 2, 1, 2, 1, 1, 2, 3
), format.spss = "F1.0", display_width = 12L, labels = c(
`not applicable` = 0,
`no stress` = 1, `low stress` = 2, `moderate stress` = 3, `very high stress` = 4
), class = c("haven_labelled", "vctrs_vctr", "double"))), row.names = c(
NA,
-10L
), class = c("tbl_df", "tbl", "data.frame"))
My desired example of result would be that:
Here in this table above everything (columns) sum up to 100% in rowwise way, as arrow shows.
I think I should somehow use pivot_longer maybe ?
I want to do it, in order to prepare a graph like this:
I can do it manually and slowly in SPSS and Excel. Here, my example data are imported form SPSS with labels coded as follows:
Any help would be greatly appreciated as I want fully transit from SPSS and Excel one day, and this is how I try to learn R.