Hello. So the following r code works in R-Studio but not in Alteryx. I have put in the full code (that I've tested to this point). The code works until you get to the bolded/italicized/underlined text. After the segmented model is ran, I then run the underlined/bolded code fine in Rstudio but it errors out in Alteryx stating:
"Error: All select() inputs must resolvel to integer column positions"
# Load the packages
package_name <- c("segmented", "dplyr", "ggplot2", "stringr", "broom")
altx.repo <- getOption("repos")
altx.repo["CRAN"] <- "https://cran.rstudio.com/"
options(repos = altx.repo)
if(package_name %in% rownames(installed.packages())==FALSE) {
install.packages(package_name)
}
lapply(package_name, library, character.only = TRUE)
# Read in the data from Alteryx into R
the_data <- read.Alteryx("#1", mode="data.frame")
write.Alteryx(the_data, 1)
#do glm
set.seed(1)
piecewise2 <- glm(freq ~ credit_tier_bucket + rba_bucket, family = quasipoisson(link="log"), data = the_data)
#do segmented
piecewise_seg2 <- segmented(piecewise2, seg.Z = ~ credit_tier_bucket + rba_bucket,
psi = list(credit_tier_bucket= c(3), rba_bucket = c(4750, 25750)))
#pull out slopes from segmented model
slopes2 <- bind_rows(lapply(slope(piecewise_seg2), tidy), .id = "variable") %>%
mutate(segment = str_extract(.rownames, "[0-9]+$")) %>%
select(variable, segment, slope = "Est.", error = "St.Err.")
Any ideas?
Solved! Go to Solution.
Can you add magrittr to your list of required packages and see if that helps?
Thanks @JohnJPS. It was actually the lack of 'tibble' package not loaded. I forgot to update this one. Thanks for replying.