Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why do I get Error in `vec_as_location()`: when computing count and full join function?

Tags:

r

dplyr

I made the objects with the variable name I want and selected variables for imported data. But when i use full_join or count, it kept giving me the Error in vec_as_location():. Does anyone know how to avoid this error? The code I wrote a month ago also got this error. But a month ago it worked.

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)

The output for dput(head(wave1)) dput(head(wave2)) would be:

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"
))  

Thank you for your help!!

like image 932
Elsie Avatar asked Feb 27 '26 09:02

Elsie


1 Answers

It seems to work fine with 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
like image 98
akrun Avatar answered Mar 02 '26 15:03

akrun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!