Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BEGIN TRY
- exec sp_execute_external_script
- @language = N'R',
- @script = N'
- # Summary Mean
- #
- # Calculates the mean of all independent variables in a table of data
- # grouped by code{code}. Note that independent variables are
- # identified as all columns matching the following pattern: the letter
- # "c" followed by a one-or-more digit number.
- #
- # @param x Table to summarize
- # @importFrom rlang .data
- #
- # @return Summary table where each distinct code{code} value is
- # represented by one row with columns for the respective means of
- # each independent variable.
- #install.packages("dplyr")
- x = clsdStudies
- code_mean <- function(x) {
- `%>%` = magrittr:: `%>%`
- dplyr::group_by(x, .data$StudyID) %>%
- dplyr::summarize_at(dplyr::vars(dplyr::matches("c\d+")), mean)
- }
- # dfcm<- code_mean
- ',
- @input_data_1 = N'
- Select
- c.StudyID, c.RespID, c.ProductNumber, c.ProductSequence, c.BottomScaleValue,
- c.BottomScaleAnchor, c.TopScaleValue, c.TopScaleAnchor, c.StudyDate,
- c.DayOfWeek, c.A, c.B, c.C, c.D, c.E, c.F,
- c.DependentVarYN, c.VariableAttributeID, c.VarAttributeName, c.[1] as c1,
- c.[2] as c2, c.[3] as c3, c.[4] as c4, c.[5] as c5, c.[6] as c6, c.[7] as c7, c.[8] as c8
- from ClosedStudyResponses c
- --Sensory Value Attributes only for mean and standard deviation analytics.
- where VariableAttributeID = 1
- and c.StudyID = @StudyID
- ',
- @input_data_1_name = N'clsdStudies',
- @params = N'@StudyID int',
- @StudyID = @StudyID_outer
- WITH RESULT SETS
- (
- ("StudyID" int, "RespID" int, "ProductNumber" int, "ProductSequence" int, "BottomScaleValue" varchar(max),
- "BottomAnchorValue" varchar(max), "TopScaleValue" varchar(max), "StudyDate" date, "DayOfWeek" varchar(max),
- "Code_Mean" int)
- )
- DECLARE @return_value int,
- @StudyID_outer int
- SELECT @StudyID_outer = 21
- EXEC @return_value = [dbo].[spCodeMeans]
- @StudyID = 21,
- @StudyID_outer = @StudyID_outer OUTPUT
- SELECT @StudyID_outer as N'@StudyID_outer'
- SELECT 'Return Value' = @return_value
- EXECUTE statement failed because its WITH RESULT SETS clause specified 1 result set(s), but the statement only sent 0 result set(s) at run time.
Add Comment
Please, Sign In to add comment