I am pulling my hair out trying to get correctly get my data from wide to long using pivot_longer.
My data currently looks like this:
# A tibble: 1 x 11
Player completetion.rank~ completion.rank.n~ ypc.rank.2020 ypc.rank.not2020 ypc.td.2020 ypc.td.not2020 ypc.int.2020 ypc.int.not2020
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Tom Brady 1 0.375 1 0.375 1 0.312 0.25 0.375
# ... with 2 more variables: ypc.sack.2020 <dbl>, ypc.sack.not2020 <dbl>
In the end, I would like the data to be organized like this:
Lastly, here is a reproducible example of the data:
structure(list(Player = "Tom Brady", completetion.rank.2020 = 1,
completion.rank.not2020 = 0.375, ypc.rank.2020 = 1, ypc.rank.not2020 = 0.375,
ypc.td.2020 = 1, ypc.td.not2020 = 0.3125, ypc.int.2020 = 0.25,
ypc.int.not2020 = 0.375, ypc.sack.2020 = 0, ypc.sack.not2020 = 0.625), row.names = c(NA,
-1L), groups = structure(list(Player = "Tom Brady", .rows = structure(list(
1L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr",
"list"))), row.names = c(NA, -1L), class = c("tbl_df", "tbl",
"data.frame"), .drop = TRUE), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
Thanks in advance. The whole pivot_longer, pivot_wider stuff throws me for a loop everytime I try to figure it out.