Good morning, and here you are:
temp <- structure(list(d1 = structure(c(NA, NA, 1, 2, 1, NA, 4, 1, 2,
2), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d2 = structure(c(NA, NA, 1, 2, 1, NA, 4, 1, 2, 2), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d3 = structure(c(NA, NA, NA, 2, 1, NA, 3, NA, 2, 2), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d4 = structure(c(NA, NA, NA, 2, NA, NA, 4, 4, 1, 1), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d5 = structure(c(3, 4, 4, 2, 1, 1, 1, 4, 4, 3), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d6 = structure(c(2, 1, NA, 2, 2, NA, 1, 1, NA, 3), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d7 = structure(c(4, 2, NA, 2, 2, NA, 3, 4, 2, 4), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d8 = structure(c(2, 2, NA, 2, 2, NA, 3, 4, 3, 4), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
)), d9 = structure(c(1, NA, NA, 2, 1, NA, NA, 1, 1, 1), format.spss = "F1.0", display_width = 12L, class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`not applicable` = 0, `not reduced` = 1,
`slightly reduced` = 2, `moderately reduced` = 3, `strongly reduced` = 4
))), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"
))
I would like for example to remove (or exclude) the label "'not applicable' = 0".
I thought that for loop should work, but it did not.
Also I want to ask if is it a faster way to write this:
attr(temp$d1, "labels") <- attr(temp$d1, "labels")[-1]
attr(temp$d2, "labels") <- attr(temp$d2, "labels")[-1]
attr(temp$d3, "labels") <- attr(temp$d3, "labels")[-1]
attr(temp$d4, "labels") <- attr(temp$d4, "labels")[-1]
attr(temp$d5, "labels") <- attr(temp$d5, "labels")[-1]
attr(temp$d6, "labels") <- attr(temp$d6, "labels")[-1]
attr(temp$d7, "labels") <- attr(temp$d7, "labels")[-1]
attr(temp$d8, "labels") <- attr(temp$d8, "labels")[-1]
attr(temp$d9, "labels") <- attr(temp$d9, "labels")[-1]
When I write it one by one it works, otherwise it does not.