Reads in a CSV of reordered attributes and levels, and applies it to a projoint_data
object.
read_labels.Rd
For users interested in reordering the attributes and levels of their conjoint data set.
First save the existing order to a CSV using save_labels
, then manually reorder them in the CSV.
Finally, use this function to read in the modified CSV and automatically apply the new order to the existing projoint_data
.
Arguments
- .data
A `projoint_data` object
- .filename
The name of a revised CSV file, originally derived from
save_labels
, after manual arrangement
Value
A projoint object of class projoint_data
ready to pass to projoint
.
Examples
library(projoint)
library(readr)
data("exampleData1")
head(exampleData1)
#> # A tibble: 6 × 185
#> ResponseId choice1_repeated_fli…¹ choice1 choice2 choice3 choice4 choice5
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 R_1M3TDihZzq9z… Community B Commun… Commun… Commun… Commun… Commun…
#> 2 R_3HtXzkcSSlfi… Community B Commun… Commun… Commun… Commun… Commun…
#> 3 R_yjYj0jtOY98X… Community B Commun… Commun… Commun… Commun… Commun…
#> 4 R_1dKd05O6FTOV… Community B Commun… Commun… Commun… Commun… Commun…
#> 5 R_1otDp642wWYl… Community A Commun… Commun… Commun… Commun… Commun…
#> 6 R_2BnD3fuJMRKZ… Community A Commun… Commun… Commun… Commun… Commun…
#> # ℹ abbreviated name: ¹choice1_repeated_flipped
#> # ℹ 178 more variables: choice6 <chr>, choice7 <chr>, choice8 <chr>,
#> # race <chr>, party_1 <chr>, party_2 <chr>, party_3 <chr>, party_4 <chr>,
#> # ideology <chr>, honesty <chr>, `K-1-1` <chr>, `K-1-1-1` <chr>,
#> # `K-1-2` <chr>, `K-1-1-2` <chr>, `K-1-3` <chr>, `K-1-1-3` <chr>,
#> # `K-1-4` <chr>, `K-1-1-4` <chr>, `K-1-5` <chr>, `K-1-1-5` <chr>,
#> # `K-1-6` <chr>, `K-1-1-6` <chr>, `K-1-7` <chr>, `K-1-1-7` <chr>, …
# Write outcome column names
outcomes <- paste0("choice", seq(from = 1, to = 8, by = 1))
outcomes <- c(outcomes, "choice1_repeated_flipped")
# Reshape the data
reshaped_data <- reshape_projoint(
.dataframe = exampleData1,
.idvar = "ResponseId",
.outcomes = outcomes,
.outcomes_ids = c("A", "B"),
.alphabet = "K",
.repeated = TRUE,
.flipped = TRUE)
# Save a CSV file (Not Run)
# save_labels(reshaped_data, "data-raw/labels_original.csv")
# Not Run: Read a revised CSV file
# reshaped_data_arranged <- read_labels(reshaped_data, "data-raw/labels_arranged.csv")