I am new to R and I have been trying to pivot a data frame I read from a CSV file. The original CSV contain 5,000 item numbers, in my sample I used the first five. My end result using pivot should present each item number as many times as the payments done and the payments type. For example, the original table look like this:
ITEM NUMBER P1 P2 P3 P4 PType1 PType2 PType3 PType4
697884 270 255 170 0 CASH CA VI
697885 100 1160 310 580 CASH AX VI CA
697886 1515 1455 1765 970 CASH AX VI CA
697887 0 0 0 0
697888 1755 3610 1950 0 AX VI CA
By using pivot I want to get a table like this:
ITEM NUMBER Payment PaymentType
697884 270 CASH
697884 255 CA
697884 170 VI
...(The next item)
My current Data Frame contain 9 variables where the item number is a NUM, the payment amount is int and the payment type is Factor. Thank you!
structure(list(ITEM.NUMBER = 697884:697888, Payment1 = c(270L,
100L, 1515L, 0L, 1755L), Payment2 = c(255L, 1160L, 1455L, 0L,
3610L), Payment3 = c(170L, 310L, 1765L, 0L, 1950L), Payment4 = c(0L,
580L, 970L, 0L, 0L), PaymentType1 = structure(c(3L, 3L, 3L, 1L,
2L), .Label = c("", "AX", "CASH"), class = "factor"), PaymentType2 = structure(c(3L,
2L, 2L, 1L, 4L), .Label = c("", "AX", "CA", "VI"), class = "factor"),
PaymentType3 = structure(c(3L, 3L, 3L, 1L, 2L), .Label = c("",
"CA", "VI"), class = "factor"), PaymentType4 = structure(c(1L,
2L, 2L, 1L, 1L), .Label = c("", "CA"), class = "factor")), .Names = c("ITEM.NUMBER",
"Payment1", "Payment2", "Payment3", "Payment4", "PaymentType1",
"PaymentType2", "PaymentType3", "PaymentType4"), row.names = c(NA,
-5L), class = "data.frame")