Consider the cprefm object:
library(conjoint)
data(chocolate)
With pivot_longer:
library(dplyr)
library(tidyr)
cprefm %>%
pivot_longer(., 1:16, "profile", "rating") %>%
head(16)
# A tibble: 16 × 2
profile value
<chr> <int>
1 profile1 14
2 profile2 15
3 profile3 5
4 profile4 2
5 profile5 1
6 profile6 11
7 profile7 3
8 profile8 10
9 profile9 16
10 profile10 13
11 profile11 12
12 profile12 7
13 profile13 6
14 profile14 9
15 profile15 4
16 profile16 8
I couldn't reproduce this with the reshape function:
cprefm |>
(\(x) reshape(x, varying = 1:16, times = names(x)[1:16], timevar = "profile",
v.names = "values", direction = "long"))() |>
(\(x) head(x, 16))()
profile values id
1.profile1 profile1 14 1
2.profile1 profile1 16 2
3.profile1 profile1 7 3
4.profile1 profile1 9 4
5.profile1 profile1 7 5
6.profile1 profile1 14 6
7.profile1 profile1 3 7
8.profile1 profile1 2 8
9.profile1 profile1 1 9
10.profile1 profile1 4 10
11.profile1 profile1 4 11
12.profile1 profile1 14 12
13.profile1 profile1 7 13
14.profile1 profile1 14 14
15.profile1 profile1 10 15
16.profile1 profile1 4 16
I have tried in many ways to modify varying argument, but I have not been able to reproduce the behavior of tidyr::pivot_longer. Note that even row.names has column names, but I wouldn't like that either.
I would like it to look identical to pivot_longer.