Я хочу стереть все атрибуты из данных и применить это решение .Однако ни one_entry()
(оригинал), ни мой one_entry2()
не будут работать, и я не понимаю, почему.
one_entry2 <- function(x) {
attr(x, "label") <- NULL
attr(x, "labels") <- NULL
}
> lapply(df1, one_entry2)
$`id`
NULL
$V1
NULL
$V2
NULL
$V3
NULL
Как мы можем это сделать?
Данные:
df1 <- setNames(data.frame(matrix(1:12, 3, 4)),
c("id", paste0("V", 1:3)))
attr(df1$V1, "labels") <- LETTERS[1:4]
attr(df1$V1, "label") <- letters[1:4]
attr(df1$V2, "labels") <- LETTERS[1:4]
attr(df1$V2, "label") <- letters[1:4]
attr(df1$V3, "labels") <- LETTERS[1:4]
attr(df1$V3, "label") <- letters[1:4]
> str(df1)
'data.frame': 3 obs. of 4 variables:
$ id: int 1 2 3
$ V1: int 4 5 6
..- attr(*, "labels")= chr "A" "B" "C" "D"
..- attr(*, "label")= chr "a" "b" "c" "d"
$ V2: int 7 8 9
..- attr(*, "labels")= chr "A" "B" "C" "D"
..- attr(*, "label")= chr "a" "b" "c" "d"
$ V3: int 10 11 12
..- attr(*, "labels")= chr "A" "B" "C" "D"
..- attr(*, "label")= chr "a" "b" "c" "d"