Given a question id, e.g. "Q4", finds all sub-questions, e.g. Q4_1, Q4_2, etc, and returns the question text that is unique to each

question_text_unique(x, Q)

Arguments

x

A surveydata object

Q

The question id, e.g. "Q4". If not supplied, returns the text for all questions.

Value

character vector

See also

Examples

# Basic operations on a surveydata object, illustrated with the example dataset membersurvey

class(membersurvey)
#> [1] "surveydata" "data.frame"

questions(membersurvey)
#>  [1] "id"        "Q1"        "Q2"        "Q3"        "Q4"        "Q5"       
#>  [7] "Q6"        "Q7"        "Q8"        "Q9"        "Q10"       "Q11"      
#> [13] "Q11_other" "Q12"       "Q13"       "Q14"       "Q15"       "Q19"      
#> [19] "Q20"       "Q20_other" "Q21"       "Q23"       "Q23_other" "Q24"      
#> [25] "Q25"       "Q26"       "Q27"       "Q30"       "Q30_other" "Q31"      
#> [31] "Q31_other" "Q32"       "Q33"       "Q35"       "weight"    "size"     

which.q(membersurvey, "Q1")
#> [1] 2 3
which.q(membersurvey, "Q3")
#>  [1]  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
which.q(membersurvey, c("Q1", "Q3"))
#>  [1]  2  3  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19

question_text(membersurvey, "Q3")
#>  [1] "[Carry out ad hoc qualitative projects] With regard to your market research work, which of these do you do at all?"                                         
#>  [2] "[Carry out ad hoc quantitative projects] With regard to your market research work, which of these do you do at all?"                                        
#>  [3] "[Design ad hoc projects but don't personally carry them out] With regard to your market research work, which of these do you do at all?"                    
#>  [4] "[Design/advise on research programmes as a whole] With regard to your market research work, which of these do you do at all?"                               
#>  [5] "[Provide project management] With regard to your market research work, which of these do you do at all?"                                                    
#>  [6] "[Summarise previous research] With regard to your market research work, which of these do you do at all?"                                                   
#>  [7] "[Carry out desk research] With regard to your market research work, which of these do you do at all?"                                                       
#>  [8] "[Provide modelling/ statistical services] With regard to your market research work, which of these do you do at all?"                                       
#>  [9] "[Provide consultancy on other specific aspects of research] With regard to your market research work, which of these do you do at all?"                     
#> [10] "[Provide field services] With regard to your market research work, which of these do you do at all?"                                                        
#> [11] "[Provide data processing services] With regard to your market research work, which of these do you do at all?"                                              
#> [12] "[Provide other part project services (interviewing, moderating, report writing)] With regard to your market research work, which of these do you do at all?"
#> [13] "[Lecture/teach] With regard to your market research work, which of these do you do at all?"                                                                 
#> [14] "[Provide training services] With regard to your market research work, which of these do you do at all?"                                                     
#> [15] "[Interim management] With regard to your market research work, which of these do you do at all?"                                                            
question_text_unique(membersurvey, "Q3")
#>  [1] "Carry out ad hoc qualitative projects"                                         
#>  [2] "Carry out ad hoc quantitative projects"                                        
#>  [3] "Design ad hoc projects but don't personally carry them out"                    
#>  [4] "Design/advise on research programmes as a whole"                               
#>  [5] "Provide project management"                                                    
#>  [6] "Summarise previous research"                                                   
#>  [7] "Carry out desk research"                                                       
#>  [8] "Provide modelling/ statistical services"                                       
#>  [9] "Provide consultancy on other specific aspects of research"                     
#> [10] "Provide field services"                                                        
#> [11] "Provide data processing services"                                              
#> [12] "Provide other part project services (interviewing, moderating, report writing)"
#> [13] "Lecture/teach"                                                                 
#> [14] "Provide training services"                                                     
#> [15] "Interim management"                                                            
question_text_common(membersurvey, "Q3")
#> [1] "With regard to your market research work, which of these do you do at all?"

# Extracting columns from a surveydata object

head(membersurvey[, "Q1"])
#>   Q1_1 Q1_2
#> 1    8    2
#> 2   35   12
#> 3   34   12
#> 4   20    9
#> 5   20    3
#> 6   36   20
head(membersurvey["Q1"])
#>   Q1_1 Q1_2
#> 1    8    2
#> 2   35   12
#> 3   34   12
#> 4   20    9
#> 5   20    3
#> 6   36   20
head(membersurvey[, "Q3"])
#>   Q3_1 Q3_2 Q3_3 Q3_4 Q3_5 Q3_6 Q3_7 Q3_8 Q3_9 Q3_10 Q3_11 Q3_12 Q3_13 Q3_14
#> 1   No   No   No   No   No   No   No   No   No   Yes    No    No    No    No
#> 2  Yes   No   No   No   No   No   No   No  Yes    No    No   Yes    No    No
#> 3  Yes  Yes   No   No   No  Yes   No   No   No    No    No    No    No    No
#> 4   No   No   No   No   No   No   No   No   No    No   Yes    No    No    No
#> 5   No   No   No   No   No   No   No   No   No    No    No    No    No   Yes
#> 6   No  Yes   No   No   No   No   No   No  Yes    No    No    No    No    No
#>   Q3_15
#> 1    No
#> 2    No
#> 3    No
#> 4    No
#> 5    No
#> 6    No
head(membersurvey[, c("Q1", "Q3")])
#>   Q1_1 Q1_2 Q3_1 Q3_2 Q3_3 Q3_4 Q3_5 Q3_6 Q3_7 Q3_8 Q3_9 Q3_10 Q3_11 Q3_12
#> 1    8    2   No   No   No   No   No   No   No   No   No   Yes    No    No
#> 2   35   12  Yes   No   No   No   No   No   No   No  Yes    No    No   Yes
#> 3   34   12  Yes  Yes   No   No   No  Yes   No   No   No    No    No    No
#> 4   20    9   No   No   No   No   No   No   No   No   No    No   Yes    No
#> 5   20    3   No   No   No   No   No   No   No   No   No    No    No    No
#> 6   36   20   No  Yes   No   No   No   No   No   No  Yes    No    No    No
#>   Q3_13 Q3_14 Q3_15
#> 1    No    No    No
#> 2    No    No    No
#> 3    No    No    No
#> 4    No    No    No
#> 5    No   Yes    No
#> 6    No    No    No

# Note that the result is always a surveydata object, even if only one column is extracted

head(membersurvey[, "id"])
#>   id
#> 1  3
#> 2  5
#> 3  6
#> 4 11
#> 5 13
#> 6 15
str(membersurvey[, "id"])
#> Classes ‘surveydata’ and 'data.frame':	215 obs. of  1 variable:
#>  $ id: num  3 5 6 11 13 15 21 22 23 25 ...
#>  - attr(*, "variable.labels")= Named chr "id"
#>   ..- attr(*, "names")= chr "id"
#>  - attr(*, "pattern")=List of 2
#>   ..$ sep    : chr "_"
#>   ..$ exclude: chr "other"