Save the attributes and levels, and their order, from a conjoint data set, to a CSV file.
save_labels.Rd
This function saves the labels for attributes and levels, which are generated by reshape_projoint
, in a CSV file. This is an important step in reorganizing labels.
Arguments
- .data
A
projoint_data
object- .filename
The name of a CSV file to be saved
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)
# Not Run: Save a CSV file
# save_labels(reshaped_data, "data-raw/labels_original.csv")