0 Replies Latest reply on Feb 23, 2018 5:12 AM by george.gousios

    tableau and r (Function expected 194 values; 97 values were returned.)

    george.gousios

      Hello,

       

      I have some data and I want to create X vs Y plot.

       

      First, I am checking if X or Y is ok, so I plot only X and then only Y.

       

      So, at X sheet , I want to plot only X values based on the filter.In the filter , I am using 2 different values (the reason for this, is that at X vs Y plot I must use many values).

      So, I want to filter the values based on the condition Id == X axis. This works fine of course, If in the filter I use this X axis value.

      But, if checkout other values also, it doesn't filter only the Id == X axis , instead, it gives me an error:

       

      Function expected 194 values; 97 values were returned.

       

      The R function works perfectly if I make an example.

      The R function for computing X is:

      library(tidyverse)
      
      computeX <- function(Timestamp, Id, X_axis, Value)
      {
        df <- data.frame(Timestamp, Id, Value)
        
        df <- df %>%
          filter(Id == X_axis) %>%
          group_by(Timestamp)
        
        # rows <- with(df, which(Id == X_axis))
        # 
        # ifelse(Id== X_axis, {df <- df %>%
        #   group_by(Timestamp)},df <- df[-rows, ])
        df$Value
        }
      

       

      If, I make a small example, let's say:

       

      the_date <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
      value <- c(1,11,111,1111,2,22,222,2222,3,33,333,3333,4,44,444,4444)
      Id <- c(1, 1,1,1,345,345,345,345,555,555,555,555,777,777,777,777)
      the_Id <- 345
      
      df <- data.frame(the_date, Id, value)
      
      df <- df %>% 
        filter(Id == the_Id) %>%
        group_by(the_date)
      df
      

       

      it gives the right results:

           the_date Id      value
             <dbl> <dbl>      <dbl>
      1      2      345      2
      2      2      345      22
      3      2      345      222
      4      2      345      2222
      

       

      But, using tableau , it gives me the error I mentioned above.

       

      The same applies for Y function:

      library(tidyverse)
      
      computeY <- function(Timestamp, Id, X_axis, Value)
      {
        df <- data.frame(Timestamp, Id, Value)
        df <- df %>%
           filter(Id != X_axis) %>%
           group_by(Timestamp, Id)
           
        #rows <- with(df, which(Id != X_axis))
        #ifelse(Id != X_axis, {df <- df %>%
        #  group_by(Timestamp, Id)}, df <- df[-rows,])
        
        df$Value
      }
      

       

      Note, that the condition in Y is Id != X axis, which again works fine in the small example.

       

      If, I try another approach, by using  the rows variable and drop the rows where the condition is not met, it shows me again the same error.

      I noticed, that if I put Id in the shapes field, it show me :

       

      Function expected 97 values; 0 values were returned.

       

      but if I don't put it , it show me :

       

      Function expected 194 values; 97 values were returned.

       

       

      So, I can't figure how to properly plot X vs Y.

      X will contain only one value  (X axis) and Y may contain multiple values (multiple Id's).

       

      Thanks!