Does anyone know if there are any ways I can turn dataset from the left side to the right side in excel macro or other programming tools?
Use R code to manipulate dataset on the left side to the one at the right side
Does anyone know if there are any ways I can turn dataset from the left side to the right side in excel macro or other programming tools?
Use R code to manipulate dataset on the left side to the one at the right side
This doesn't exactly match what you are looking for, but further data analysis might be easier formatted this way
library(tidyverse)
df = read_csv("Downloads/test.csv")
df = df %>% group_by(Transaction, Item) %>% summarize(count_value = n())
result = df %>% pivot_wider(names_from = "Item", values_from = "count_value", values_fill = 0)
I pivot data this way:
library(tidyverse)
df <- data.frame(Transaction=c(1,2,2),
Item=c("Apple", "Banana", "Coconut"))
df %>%
group_by(Transaction) %>%
mutate(ItemNumber = paste0("Item", row_number())) %>%
pivot_wider(names_from = ItemNumber,
values_from = Item)
# Transaction Item1 Item2
#1 1 Apple NA
#2 2 Banana Coconut