Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

R-tool outputs string values in result as double

Brayndasilva
7 - Meteor

Hi,

 

I have designed a simple flow that processes soccer game data with the R-tool to determine a top 10 standing. The R code I wrote works fine, but for some reason it outputs a column which contains string values as numbers (Double) instead.

 

Here's the output on Alteryx:                                                     And here's the output on my R IDE with the same code:

output_alteryx.PNG

 

                output_R.PNG

 

 

 

 

The code I wrote reads the data as a dataframe and loops through every row to calculate a certain score for the clubs in that match. The results are appended to a list called 'scores' which is then converted into a dataframe as output.

 

Any reason why Alteryx is giving me numerical 'club' output when it should be string values?

 

Here's the code if it helps:

 

data <- subset(read.Alteryx("#1", mode="data.frame"), Seizoen == "2010-2011")

#calculate scores based on win/draft and append result to new list.
scores <- list();
for(i in 1:nrow(data)) {
  if(as.numeric(data[i, 5]) == as.numeric(data[i, 6])) {
    scores[[(length(scores) + 1)]] <- list(club = data[i, 3],score = 1)
    scores[[(length(scores) + 1)]] <- list(club = data[i, 4],score = 1)
  }
  
  else if(as.numeric(data[i, 5]) > as.numeric(data[i, 6])) {
    scores[[(length(scores) + 1)]] <- list(club = data[i, 3],score = 3)
  }
  
  else if(as.numeric(data[i, 5]) < as.numeric(data[i, 6])) {
    scores[[(length(scores) + 1)]] <- list(club = data[i, 4],score = 3)
  }
}

#convert list into dataframe and clean up column names.
scores <- data.frame(matrix(unlist(scores), nrow=length(scores), byrow=TRUE))
colnames(scores)[1] = "club"
colnames(scores)[2] = "score"

#calculate a cumulative score grouped on club.
scores <- transform(scores, cumulatieve_score = ave(score,club,FUN=cumsum))

write.Alteryx(scores, 1)

 

 

Kind regards,

 

Brayn

1 REPLY 1
Brayndasilva
7 - Meteor

See the attached Alteryx file for a similiar flow with a small set of test data.

 

We have 7 rows of soccer match data. When a match is won the club is awarded 3 points and when the match ends as a draw both clubs are awarded 1 point.

 

R indexes columns starting from 1 so:

data[i, 3] = Home_club

data[i, 4] = Out_club

data[i, 5] = Home_score

data[i, 6] = Out_score

 

index 3 and 4 are appended under "club" and are shown correctly when run in R, but in alteryx it returns a numeric value as described in my original post.

 

Hope this helps

 

Labels