Extract or replace subsets of surveydata, ensuring that the varlabels stay in synch.

Share:

Description

The surveydata package makes it easy to extract specific questions from a surveydata object. Because survey data typically has question names like Q1_a, Q1_b, Q1_c the extract method for a surveydata object makes it easy to extract all columns by simply specifing "Q1" as the argument to the column index.

Usage

1
2
3
4
5
6
7
8
  ## S3 method for class 'surveydata'
 x[i, j, drop = FALSE]

  ## S3 replacement method for class 'surveydata'
x[i, j] <- value

  ## S3 replacement method for class 'surveydata'
x$name <- value

Arguments

i

row index

j

column index

drop

logical. Passed to [.data.frame. Note that the default is FALSE.

...

Other arguments passed to [.data.frame

x

surveydata object

name

Names of columns

value

New value

Details

Extraction is similar to data frames, with three important exceptions:

  • The column argument j is evaluated using which.q and will return all columns where the column names match the pattern.

  • The drop argument is FALSE. Thus the result will always be a surveydata object, even if only a single column is returned.

  • All extraction methods retain the pattern and varlabels arguments.

See Also

surveydata-package, varlabels

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
names(membersurvey)
head(membersurvey["Q1"])
head(membersurvey[c("Q1", "Q2")])
head(membersurvey[membersurvey$Q2=="2009", c("Q1", "Q2")])

# The pattern is used to extract columns

pattern(membersurvey)

grep("Q20", names(membersurvey), value=TRUE)
head(membersurvey["Q20"])
head(membersurvey["Q20_other"])

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.