DB <- structure(list(orderItemID = 1:10, CustomerName = structure(c(1L,
1L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 6L), .Label = c("Alex", "Bert",
"Corel", "Dennis", "Edgar", "Fred"), class = "factor"), OrderID = structure(c(5L,
6L, 1L, 2L, 2L, 8L, 7L, 7L, 4L, 3L), .Label = c("14", "17", "33",
"56", "58", "62", "89", "9"), class = "factor"), ArticleDescription = structure(c(10L,
5L, 1L, 7L, 8L, 3L, 4L, 2L, 9L, 6L), .Label = c("Adidas Jacket",
"Adidas Shoes", "Aesics Shoes", "Boss Jeans", "Lee T-Shirt",
"Nike Airs", "Nike Shoes", "Puma Backpack", "Puma Socks", "Wrangler Jeans"
), class = "factor")), .Names = c("orderItemID", "CustomerName",
"OrderID", "ArticleDescription"), row.names = c(NA, -10L), class = "data.frame")
預期的結果:
output <- structure(list(orderItemID = 1:10, Name = structure(c(1L, 1L,
2L, 3L, 3L, 4L, 4L, 4L, 5L, 6L), .Label = c("1", "2", "3", "4",
"5", "6"), class = "factor"), NumberOfOrders = structure(c(1L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L), .Label = c("1", "2"), class = "factor"),
ArticleDescription = structure(c(10L, 5L, 1L, 7L, 8L, 3L,
4L, 2L, 9L, 6L), .Label = c("Adidas Jacket", "Adidas Shoes",
"Aesics Shoes", "Boss Jeans", "Lee T-Shirt", "Nike Airs",
"Nike Shoes", "Puma Backpack", "Puma Socks", "Wrangler Jeans"
), class = "factor")), .Names = c("orderItemID", "Name",
"NumberOfOrders", "ArticleDescription"), row.names = c(NA, -10L
), class = "data.frame")
早上好!
這次我需要用1開頭的數字替換CustomerName
- 同一個名字應該有相同的數字 - 下一個名字應該有下一個更高的數字。此外,OrderID
應該通過特定客戶訂購的訂單數來重播 - 在這種情況下,當不同商品的訂單ID相等時,它是一個訂單(例如,Alex做了2個訂單(在他訂購的第一個訂單中「Wrangler牛仔褲「,第二個是」Lee T-Shirt「);丹尼斯也做了2個訂單(第一個訂購了」Aesics Shoes「,第二個訂購了」Boss Jeans「和」Adidas Shoes「)最後,我想繼續使用dplyr
的ArticleDescription
不變
請修復您的樣品。他們會拋出錯誤 – Sotos
現在我的最大希望是什麼:/ – Jarvis