I am running pivot_longer on multiple columns (i.e. two character columns and one numeric). I am encountering an error related to the class mismatch.
I
We can specify the values_ptype in this case (as the value columns differ in types)
library(ggplot2)
library(tidyr)
library(dplyr)
small_diamonds %>%
pivot_longer( - row_num,
names_to = "key",
values_to = "val", values_ptypes = list(val = 'character'))
# A tibble: 161,820 x 3
# row_num key val
#
# 1 1 cut Ideal
# 2 1 color E
# 3 1 price 326
# 4 2 cut Premium
# 5 2 color E
# 6 2 price 326
# 7 3 cut Good
# 8 3 color E
# 9 3 price 327
#10 4 cut Premium
# … with 161,810 more rows