I have survey data with a weighting variable called weight
that I want to use on my dataset. The survey
package unfortunately doesn't work as I was thinking. What I finally need is to
- plot a (bar)chart (with percentage of the distribution on y-axis) that considers the weighting but keeps the levels of the factor (on the x-axis).
- somehow export the weighted dataset to SPSS.
Is there a way this could work? A solution even with the survey
package would be ok as I have no objectives but still couldn't get it to work.
I know there are some posts regarding weighting issues, but I couldn't find a fitting solution to my issue. Thanks for your help.
# create data
surveydata <- as.data.frame(replicate(1,sample(0:1,1000,rep=TRUE)))
# change values of columns
surveydata$V1 <- (replicate(1,sample(c(0.5,1,1.5),1000,rep=TRUE)))
surveydata$V2 <- as.factor(sample(3, size = nrow(surveydata), replace = TRUE))
levels(surveydata$V2)[levels(surveydata$V2)=="1"] <- "a"
levels(surveydata$V2)[levels(surveydata$V2)=="2"] <- "b"
levels(surveydata$V2)[levels(surveydata$V2)=="3"] <- "c"
# rename columns
colnames(surveydata)[1] <- "weight"
colnames(surveydata)[2] <- "variable"