0

I am using the Survey Package in R to do some initial descriptive stats for my dissertation. With the outputs for both the svymean and the barplot, I would like the value labels to be displayed for the variable-it would make the descriptive statistics much easier to interpret. Instead of the output labels of: F1RTRCC1, F1RTRCC2-I would like to see the value labels of "academic" and "occupational" to be displayed.

How do I go about making this happen? I am including a minimal reproducible example with a small subset of my actual data:

#Calling Survey Package

library (survey)

#Using dput to display a subset of my actual data

MRE1 <- structure(list(ï..STU_ID = c(101101L, 101102L, 101104L, 101105L,  101106L, 101107L), 
                        PSU = c(1L, 1L, 1L, 1L, 1L, 1L), STRAT_ID = c(101L, 
                        101L, 101L, 101L, 101L, 101L), BYSCTRL = c(1L, 1L, 1L, 1L, 1L, 
                        1L), G10COHRT = c(1L, 1L, 1L, 1L, 1L, 1L), F1RTRCC = c(2L, 1L, 
                        4L, 2L, 2L, 4L), F1SEX = c(2L, 2L, 2L, 2L, 2L, 1L), F1RACE = c(5L, 
                        2L, 7L, 3L, 4L, 4L), F1PARED = c(5L, 5L, 2L, 2L, 1L, 2L), F1SES2QU = c(2L, 
                        4L, 1L, 1L, 1L, 1L), F1HIMATH = c(5L, 6L, 6L, 4L, 5L, 4L), F1RGPP2 = c(2L, 
                        4L, 4L, 4L, 4L, 1L), F3ATTAINMENT = c(3L, 10L, 6L, 4L, 4L, 3L
                        ), F3EDSTAT = c(5L, 5L, 5L, 2L, 2L, 5L)), .Names = c("ï..STU_ID", 
                        "PSU", "STRAT_ID", "BYSCTRL", "G10COHRT", "F1RTRCC", "F1SEX", 
                        "F1RACE", "F1PARED", "F1SES2QU", "F1HIMATH", "F1RGPP2", "F3ATTAINMENT", 
                        "F3EDSTAT"), row.names = c(NA, 6L), class = "data.frame")  

#Svymean of Variable F1RTRCC
#There is an error coming here: Error in UseMethod("svymean", design) : 
#no applicable method for 'svymean' applied to an object of class "data.frame"-I 
#think this is likely related to my dput subset of my data, as when I am using 
#this function with my full dataset, this error does not display.

CC <- svymean(~F1RTRCC, MRE1, na.rm=T)
CC

#Barplot for F1RTRCC 

barplot(CC)

With the outputs for both the svymean and the barplot, I would like the value labels to be displayed.
Instead of F1RTRCC1, F1RTRCC2-I would like to see the value labels of "academic" and "occupational" to be displayed.
How do I go about making this happen?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • You should include the reproducible example in the question itself rather than linking to an Rmd file. Check out these [suggestions for making a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Your example is somewhat confusing because you have an error on the `svymean` call which isn't even the problem you are describing in the question. – MrFlick Jul 27 '16 at 15:35
  • Thank you for your recommendations. I tried to include the reproducible example in the question by editing it. I also checked out the suggestions for reproducible examples. I am not sure how to clean up that error, but as my comments indicate, it only occurs with this dput subset I am using here-with my full dataset-it is not an issue. My main concern is achieving the variable value labels. Thank you. – Courtney B. Jul 28 '16 at 04:44
  • If your reproducible example produces a different error, then it doesn't reproducible your problem so it isn't helpful. The `svymean()` function expects a `survey.design` or `svyrep.design` object as the second parameter, not a `data.frame` which is what you included in your example. – MrFlick Jul 28 '16 at 04:59
  • Hi Mr. Flick, I have improved my code by adding in the svyrep.design object and it runs great in an Rmd. file, but the dput subset of the head of the dataset with the replicates is quite lengthy and now I keep coming up with an "unexpected character" error in the svymean call when I copy and paste into the R console from an R Script file, but when I have the exact same thing in an Rmd file-it runs without that error. Here is the link to that Rmd file; https://drive.google.com/file/d/0B5fHCR5TGRjaZ29wNzR0cF9YRXc/view?usp=sharing – Courtney B. Jul 28 '16 at 17:17
  • Any help is greatly appreciated. My only experience thus far is with SPSS and I have a feeling that the reason the variable value labels are not appearing is due to either the way I read the dataset into R: elsq1ch<-read.table (file="els-Q1-04-21-16.dat", header = TRUE, sep = "\t", quote = "\"", dec =".") or I am not specifying some detail that is required to manually assign labels to the values of the variables. – Courtney B. Jul 28 '16 at 17:21
  • I solved the value labeling issue with this code: MRE3$F1RTRCC <- factor(MRE3$F1RTRCC, levels = c(1,2,3,4), labels = c("Academic", "Occupational", "General", "Other")) levels(MRE3$F1RTRCC), however, the variable name of F1RTRCC sticks with the newly assigned value labels-F1RTRCCAcademic,F1RTRCCOccupational, etc. How can I get the value labels to stand alone as Academic, Occupational, etc? Thank you. – Courtney B. Jul 29 '16 at 18:51

0 Answers0