Hi.
I'm trying to do some simple ABC Analysis on my inventory and the code was working pretty well on R / R Studio. However, when trying to replicate that on Alteryx R Tool, it gives me this error below:
Error: R (660): Error in `$<-.data.frame`(`*tmp*`, "Classification_2", value = "C - C") : Info: R (660): replacement has 1 row, data has 0 Info: R (660): Calls: $<- -> $<-.data.frame
The code I have is pretty simple: I first classify the products into A, B and C using the ABCanalysis package, separate the databases to classify them and do it again for a second level, like A - A, A - B, A - C and so on. The code is this one below:
library("ABCanalysis") #Import databases df <- read.Alteryx("#1", mode="data.frame") #################################################### #ABC Analysis (1st level of classification) abc <- ABCanalysis(df$Revenue) #Separate ABC datasets SetA <- df[abc$Aind,] SetB <- df[abc$Bind,] SetC <- df[abc$Cind,] #Insert classifications into datasets SetA$Classification_1 <- as.character("A") SetB$Classification_1 <- as.character("B") SetC$Classification_1 <- as.character("C") #################################################### #ABC Analysis (2nd level of classification) abc_SetA <- ABCanalysis(SetA$Revenue) abc_SetB <- ABCanalysis(SetB$Revenue) abc_SetC <- ABCanalysis(SetC$Revenue) #Separate ABC datasets SetA_A <- SetA[abc_SetA$Aind,] SetA_B <- SetA[abc_SetA$Bind,] SetA_C <- SetA[abc_SetA$Cind,] SetB_A <- SetB[abc_SetB$Aind,] SetB_B <- SetB[abc_SetB$Bind,] SetB_C <- SetB[abc_SetB$Cind,] SetC_A <- SetC[abc_SetC$Aind,] SetC_B <- SetC[abc_SetC$Bind,] SetC_C <- SetC[abc_SetC$Cind,] #Insert classifications into datasets SetA_A$Classification_2 <- as.character("A - A") SetA_B$Classification_2 <- as.character("A - B") SetA_C$Classification_2 <- as.character("A - C") SetB_A$Classification_2 <- as.character("B - A") SetB_B$Classification_2 <- as.character("B - B") SetB_C$Classification_2 <- as.character("B - C") SetC_A$Classification_2 <- as.character("C - A") SetC_B$Classification_2 <- as.character("C - B") SetC_C$Classification_2 <- as.character("C - C") #################################################### #Export for Alteryx write.Alteryx(SetA_A, 1) write.Alteryx(SetA_B, 1) write.Alteryx(SetA_C, 1) write.Alteryx(SetB_A, 1) write.Alteryx(SetB_B, 1) write.Alteryx(SetB_C, 1) write.Alteryx(SetC_A, 1) write.Alteryx(SetC_B, 1) write.Alteryx(SetC_C, 1)
I do it for 6 countries. All the process and databases are the same, but it happens for some of them and not for others, pretty random.
Any suggestions?
Thanks.