unexpected symbol using survey package

Hi, I am trying to put this into R, but it keeps telling me I have an "unexpected symbol".

test <- svydesign(id = ~CLUSTER2, weights = ~GSWGT4_2, data = dataset[is.na(dataset$GSWGT4_2)==F,]
svymean(~age, test)

I think you are missing a parentheses. I've added one after you specify the data.

test <- svydesign(id = ~CLUSTER2, weights = ~GSWGT4_2, data = dataset[is.na(dataset$GSWGT4_2)==F,])
svymean(~age, test)

Thank you!! Now for some reason it says object "age" not found..

R is case-sensitive. I suggest checking for which variables are on your dataset by doing the following. Perhaps the variable is AGE, Age, or some other configuration or not there at all.

names(dataset)

1 Like

Thank you! You are a lifesaver!

Glad I can help. A bit of advice, I suggest using the package srvyr as the syntax is much more straightforward. It will get you the same results

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.