Error: "Columns of type list not supported yet" in R when trying to write dta file using the haven package
Error: "Columns of type list not supported yet" in R when trying to write dta file using the haven package
我的三个专栏表现得很奇怪,即使它们在我的数据框中被声明为 numeric
。我也无法使用 colnames
更改这些列的名称
我的步数:
install.packages("避风港")
图书馆(天堂)
write_dta(data = df, "path/mydata.dta")
我的数据框df
structure(list(WeekDaysAbove28 = structure(list(`tapply(testdlong$value > 28, ceiling(seq(nrow(testdlong))/7), ` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20"), class = "data.frame"), WDA28 = structure(list(`tapply(testdlong$value > 28, ceiling(seq(nrow(testdlong))/7), ` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20"), class = "data.frame"), WDBM5 = structure(list(`tapply(testdlong$value < -5, ceiling(seq(nrow(testdlong))/7), ` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20"), class = "data.frame")), row.names = c(NA, 20L), class = "data.frame")
错误 “尚不支持类型列表的列” 建议我需要以某种方式更改这些列中给出的信息,但我无法弄清楚到底出了什么问题。我有 294 列,当这三列被排除在外时,write_dta
命令工作正常
您有嵌套数据框。这很可能是因为您 运行 上一步(使用 tapply
)不正确。试试这个:
result <- data.frame(lapply(df, `[[`, 1))
result
# WeekDaysAbove28 WDA28 WDBM5
#1 0 0 0
#2 0 0 0
#3 0 0 0
#4 0 0 0
#5 0 0 0
#6 0 0 0
#7 0 0 0
#8 0 0 0
#9 0 0 0
#10 0 0 0
#11 0 0 0
#12 0 0 0
#13 0 0 0
#14 0 0 0
#15 0 0 0
#16 0 0 0
#17 0 0 0
#18 0 0 0
#19 0 0 0
#20 0 0 0
str(result)
#'data.frame': 20 obs. of 3 variables:
# $ WeekDaysAbove28: int 0 0 0 0 0 0 0 0 0 0 ...
# $ WDA28 : int 0 0 0 0 0 0 0 0 0 0 ...
# $ WDBM5 : int 0 0 0 0 0 0 0 0 0 0 ...
我们可以使用
library(purrr)
map_dfr(df, pluck, 1)
我的三个专栏表现得很奇怪,即使它们在我的数据框中被声明为 numeric
。我也无法使用 colnames
我的步数:
install.packages("避风港")
图书馆(天堂)
write_dta(data = df, "path/mydata.dta")
我的数据框df
structure(list(WeekDaysAbove28 = structure(list(`tapply(testdlong$value > 28, ceiling(seq(nrow(testdlong))/7), ` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20"), class = "data.frame"), WDA28 = structure(list(`tapply(testdlong$value > 28, ceiling(seq(nrow(testdlong))/7), ` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20"), class = "data.frame"), WDBM5 = structure(list(`tapply(testdlong$value < -5, ceiling(seq(nrow(testdlong))/7), ` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20"), class = "data.frame")), row.names = c(NA, 20L), class = "data.frame")
错误 “尚不支持类型列表的列” 建议我需要以某种方式更改这些列中给出的信息,但我无法弄清楚到底出了什么问题。我有 294 列,当这三列被排除在外时,write_dta
命令工作正常
您有嵌套数据框。这很可能是因为您 运行 上一步(使用 tapply
)不正确。试试这个:
result <- data.frame(lapply(df, `[[`, 1))
result
# WeekDaysAbove28 WDA28 WDBM5
#1 0 0 0
#2 0 0 0
#3 0 0 0
#4 0 0 0
#5 0 0 0
#6 0 0 0
#7 0 0 0
#8 0 0 0
#9 0 0 0
#10 0 0 0
#11 0 0 0
#12 0 0 0
#13 0 0 0
#14 0 0 0
#15 0 0 0
#16 0 0 0
#17 0 0 0
#18 0 0 0
#19 0 0 0
#20 0 0 0
str(result)
#'data.frame': 20 obs. of 3 variables:
# $ WeekDaysAbove28: int 0 0 0 0 0 0 0 0 0 0 ...
# $ WDA28 : int 0 0 0 0 0 0 0 0 0 0 ...
# $ WDBM5 : int 0 0 0 0 0 0 0 0 0 0 ...
我们可以使用
library(purrr)
map_dfr(df, pluck, 1)