gpt4 book ai didi

r - 为什么我在 `vec_as_location()` : when computing count and full join function? 中出现错误

转载 作者:行者123 更新时间:2023-12-05 05:37:09 25 4
gpt4 key购买 nike

我用我想要的变量名创建了对象,并为导入的数据选择了变量。但是当我使用 full_join 或 count 时,它一直在 vec_as_location(): 中给我错误。有谁知道如何避免这个错误?我一个月前写的代码也出现了这个错误。但一个月前它奏效了。

vars <- c("pidp", "cb_age")

wave1 <- read_dta("./data/dresp_w.dta",
col_select = vars)
vars2 <- c("pidp", "cb_sex")

wave2 <- read_dta("./data/dresp_w.dta",
col_select = vars2)
wave12 <- full_join(wave1, wave2, by = "pidp")
count(wave1,cb_sex)

dput(head(wave1)) 的输出dput(head(wave2)) 将是:

structure(list(pidp = structure(c(76165, 280165, 599765, 732365, 
1587125, 3424485), label = "Cross-wave Person Identifier (Public Release)", format.stata = "%12.0g"),
cb_age = structure(c(37, 40, 33, 34, 54, 84), label = "Age - derived", format.stata = "%8.0g", labels = c(Missing = -9,
Inapplicable = -8, Refusal = -2, `Don't know` = -1), class = c("haven_labelled",
"vctrs_vctr", "double"))), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
structure(list(pidp = structure(c(76165, 280165, 599765, 732365, 
1587125, 3424485), label = "Cross-wave Person Identifier (Public Release)", format.stata = "%12.0g"),
cb_sex = structure(c(2, 2, 2, 1, 2, 2), label = "Respondent sex", format.stata = "%8.0g", labels = c(Missing = -9,
Inapplicable = -8, Refusal = -2, `Don't know` = -1, Male = 1,
Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"
))), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))

谢谢你的帮助!!

最佳答案

它似乎与 dplyr packageVersion -1.0.9 一起工作得很好

dplyr::count(wave2, cb_sex)
# A tibble: 2 × 2
cb_sex n
<dbl+lbl> <int>
1 1 [Male] 1
2 2 [Female] 5

关于r - 为什么我在 `vec_as_location()` : when computing count and full join function? 中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73177401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com