5 Replies Latest reply on Mar 13, 2018 2:00 PM by Shiva Wagle

# Calculation of mean only for the unique participants in the longdata- using R and tableau integration

Hello all,

I am new in tableau and R integration.

I am trying to display mean of Max Signon  only for the unique participant.Here the tableau data is in the long format. Therefore,I use the following R code

d1<-crating the dataframe

d2<-keeping only the unique participants

Here I am expecting  mean of Max Sign on only for the unique participants,  however I am getting mean for the total participants(not for the unique),

Could you please comment on my coding

Thank you very much,

• ###### 1. Re: Calculation of mean only for the unique participants in the longdata- using R and tableau integration

Hi Shiva,

Your problem is that you are aggregating all your data before you send it to R.

If you go into the analysis menu, and uncheck Aggregate Measures or add a RowID to your data and put that row into your Viz as continuous dimension, you won't have that problem.

Notice, that you can not add a RowID as a discrete dimension because then it would partition or data by the RowID and send each row to your R calculation separately.

To debug problems like this in the future, you can run R.exe from a console window, call Rserve() and then add print statements to the scripts embedded in your calculations.

This way you can print intermediate results which will appear in your console window.

Your problem becomes obvious when you print.arg2 and see a single average of all your MaxSignon values.

I've added a super simple example.

The data has just four rows with the 2nd and 4th both being for Participant ID 2.

The average of Max Signon with all rows averaged by Tableau and then averaged again by your script is 12.5.

The average of Max Signon computed by your script with the fourth duplicate row deleted is 10.

2 of 2 people found this helpful
• ###### 2. Re: Calculation of mean only for the unique participants in the longdata- using R and tableau integration

Thank you very much Scott,

Shiva

• ###### 3. Re: Calculation of mean only for the unique participants in the longdata- using R and tableau integration

There is some issue in opening the file,

thanks,

Shiva

• ###### 4. Re: Calculation of mean only for the unique participants in the longdata- using R and tableau integration

Oops, the data wouldn't be the issue since it is a packaged workbook.

But, I accidentally loaded a workbook from a version that you don't have.

I'll recreate it as version 10.something

• ###### 5. Re: Calculation of mean only for the unique participants in the longdata- using R and tableau integration

Thank you very much Scott for this. Also,I s there any way I could display only one value(10.00) rather than displaying 4  values?

thanks ,

Shiva