First thing to try is to change this line
Tableau already passes arguments as vectors. When you do the above, R will put everything in one column with a long name like c...arg1..arg2..
If you remove the c() that wraps it all, you will get the data frame that has these as individual columns which I think is what you're trying to do here.
Then when you want to get the results back into Tableau you just need to pull the column containing the predictions as opposed to the full data.frame.
I have an example workbook you can download here that contains decision trees, regression trees and random forests in Tableau with R integration.
Thanks Bora Beran, it's working now. But, I'm facing another problem (not an error though ). As you can see in the original post, I'm trying to predict for Data16 using Data15, both of which are subsets of the imported dataset in Tableau.
My data looks like this,
Test Variable 1 Variable 2 Variable 3 Variable 4 Variable 5 Variable 6 Variable 7 Variable 8 Variable 9 Year Variable 11 ABCDE2015 0.578415 0.006129 0.82549 0.835607 0.189075 0.538328 0.894697 0.895335 0.560702 2015 0.151732 ABCDE2016 0.64591 0.321047 0.709445 0.039521 0.321715 0.737296 0.178409 0.731013 0.289293 2016 0.586291
where I'm predicting the value of one of the variables for each Test value. So, I guess I'll have to calculate yhat along each Test. The problem with this approach is the R script will be returning the values for the Test values coming from Data16 whereas my row labels have data from the master data set. To encounter this error, I ran the predict function for Data15 as well and took the appended result as R script output, like below:
yhat <- predict(rf, Data16)
yhat1 <- predict(rf, Data15)
As a result, my Tableau output shows predicted values for both Data15 and Data16- which is not ideal. And I can't have year as filter here since it'll filter the data in R script as well. Is there any way to filter only the displayed output for only 2016 but not limit the data used by R script?