Home > other >  R - Alteryx - All columns in a tibble must be vectors
R - Alteryx - All columns in a tibble must be vectors

Time:01-23

I'm using R on Alteryx to perform some statical analysis from my data.

It appears the error message " ! All Columns in a tibble must be vectors." as the following error message:

Error message

Does anybody can help me?

Below is my entire code:

library("tibble")

# Calling Data from Connection #1
data <- read.Alteryx("#1")

average_wilcox <- c("1","1","1","1","1","1","1")

# Creating data frame for in case it comes an empty table
df <- data.frame(average_wilcox)

#Verify if p-value is empty
# In case is different that empty, executes the steps for the Hypothesis Test for non-normal data
if (length(data$p.value) == 0) {
write.Alteryx(df, 1)
} else if (data$p.value != '') {
Week1 <- read.Alteryx("#2", mode="data.frame")
"&"
Week2 <- read.Alteryx("#3", mode="data.frame")

# MANN WHITNEY TEST (AVERAGE TEST FOR NON NORMAL)

Week1_data <- Week1$Wk1_feature_value
Week2_data <- Week2$Wk2_feature_value

# DEFINE VECTORS
week1 <- c(Week1_data)
week2 <- c(Week2_data)

merge(cbind(Week1, X=1:length(week1)),
      cbind(Week2, X=1:length(week2)), all.y =T) [-1]

# MANN WHITNEY TEST (MEAN TEST FOR NON NORMAL)
average_wilcox <- wilcox.test(week1,week2, alternative='two.sided', conf.level=.95)

average_test <- tibble(average_wilcox) 

average_test[] <- lapply(average_test, as.character)

write.Alteryx(average_test, 1)
}

#### NORMAL HYPOTHESIS TEST ####

# Calling Data from Connection #4
data1 <- read.Alteryx("#4")
df1 <- data.frame(Date=as.Date(character()),"p.value"=character(),User=character(),stringsAsFactors=FALSE)

# Verify if p-value is empty
# In case if different than empty, executes the steps for the Hypothesis Test for normal data
if(length(data1$p.value) == 0) { 
write.Alteryx(df1, 3)
} else if (data1$p.value != '') { 
Week1 <- read.Alteryx("#2", mode="data.frame") 
"&"
Week2 <- read.Alteryx("#3", mode="data.frame") 

# T TEST (MEAN TEST FOR NORMAL)

Week1_data <- Week1$Wk1_feature_value 
Week2_data <- Week2$Wk2_feature_value 

# DEFINE VECTORS
week1 <- c(Week1_data) 
week2 <- c(Week2_data) 

# T TEST (MEAN TEST FOR NORMAL)
t_test <- t.test(week1,week2, alternative='two.sided',conf.level=.95) 

write.Alteryx(t_test,3)
}

Please, anybody knows what I have to do?

Many thanks,

Wil

CodePudding user response:

Reason is that both wilcox.test and t.test returns a list of vectors, which may have difference in length. So, using that list in write.Alteryx is triggering the error as it expects a data.frame/tibble/data.table. e.g.

> str(t.test(1:10, y = c(7:20)))
List of 10
 $ statistic  : Named num -5.43
  ..- attr(*, "names")= chr "t"
 $ parameter  : Named num 22
  ..- attr(*, "names")= chr "df"
 $ p.value    : num 1.86e-05
 $ conf.int   : num [1:2] -11.05 -4.95
  ..- attr(*, "conf.level")= num 0.95
 $ estimate   : Named num [1:2] 5.5 13.5
  ..- attr(*, "names")= chr [1:2] "mean of x" "mean of y"
 $ null.value : Named num 0
  ..- attr(*, "names")= chr "difference in means"
 $ stderr     : num 1.47
 $ alternative: chr "two.sided"
 $ method     : chr "Welch Two Sample t-test"
 $ data.name  : chr "1:10 and c(7:20)"
 - attr(*, "class")= chr "htest"
> x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46)
> y <- c(1.15, 0.88, 0.90, 0.74, 1.21)
> str(wilcox.test(x, y, alternative = "g") )
List of 7
 $ statistic  : Named num 35
  ..- attr(*, "names")= chr "W"
 $ parameter  : NULL
 $ p.value    : num 0.127
 $ null.value : Named num 0
  ..- attr(*, "names")= chr "location shift"
 $ alternative: chr "greater"
 $ method     : chr "Wilcoxon rank sum exact test"
 $ data.name  : chr "x and y"
 - attr(*, "class")= chr "htest"

An option is to convert the output from both t.test and wilcox.test to a data.frame/tibble. tidy/glance from broom does this

...
library(broom)
average_wilcox <- tidy(wilcox.test(week1,week2, alternative='two.sided', conf.level=.95))
write.Alteryx(average_wilcox, 1)
...
t_test <- tidy(t.test(week1,week2, alternative='two.sided',conf.level=.95))

write.Alteryx(t_test,3)
  • Related