Unexpected error in sql machine learning,reshape2

HI Everyone :slight_smile:

I have a problem with an R function that I am trying to execute on an SQL function.
I am attaching screenshots with eror message.

In RSudio, the code works without a problem, so I don't understand what causes this problem.

ALTER PROCEDURE HI (@threshold float = 0.1)
	exec sp_execute_external_script
		  @language = N'R',
		  @script = N'	
			 dd = dcast(InputDataSet, VendorNumber ~ Digits, value.var="Freq");
			 OutputDataSet = cbind(
				apply(dd[,-1], 1, function(xx) chisq.test(xx, p=(log(1+1/(1:9))/log(10)))$p.value)); ## Equation using Benford law
			 colnames(OutputDataSet) <- c("VendorNumber", "Digit1", "Digit2", "Digit3", "Digit4",
											"Digit5", "Digit6", "Digit7", "Digit8", "Digit9", "Pvalue");
			OutputDataSet <- subset(OutputDataSet, Pvalue < threshold);
		  @input_data_1 = N'
	select VendorNumber, Digits, Freq
	  from [BenfordFraud].VendorInvoiceDigits(default)
	order by VendorNumber asc, Digits asc;
		  @params = N'@threshold float',
		  @threshold = @threshold
	with result sets (( VendorNumber varchar(10),
	   Digit1 int, Digit2 int, Digit3 int, Digit4 int, Digit5 int, Digit6 int, Digit7 int, Digit8 int, Digit9 int,
	   Pvalue float));

Thank you in advance for your help

I know that I have problem with only function 'dcast'.
It's working in RStudio, but not in shown above procedure.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.