T-SQL中R外部脚本的结果严重舍入

时间:2018-04-04 12:58:21

标签: r tsql machine-learning summary sql-server-2017

我有关于各种费用的数据(costs_q_active),我需要特别使用R中的summary函数。 我在R:

中使用这个陈述
mysummary <- cbind.data.frame(
S = c("Minimum", "1st Quartal", "Median", "Mean", "3rd Quarter", "Maximum")
, do.call(
    cbind
    , lapply(costs_q_active, summary)
    )
)

给出正常值,如24921.823444。但是当我在T-SQL过程sp_execute_external_script中使用此代码时,值会四舍五入到前四位数而不是整数等等(所以我得到数字24920)。

EXEC sp_execute_external_script @language =N'R', @script=N'
costs_q <- InputDataSet
colnames(costs_q) <- c("DimArticleId", "Quantity", "Material", "Dilce", "Kooperace", "Mzdy", "Naklady_pracoviste")
costs_q$DimArticleId <- as.character(costs_q$DimArticleId)
costs_q_active <- costs_q[,c("Quantity", "Material", "Dilce", "Kooperace", "Mzdy", "Naklady_pracoviste")]
mysummary <- cbind.data.frame(
    Statistic = c("Minimum", "1st Quartal", "Median", "Mean", "3rd Quarter", "Maximum")
    , do.call(
        cbind
        , lapply(costs_q_active, summary)
        )
    )

OutputDataSet <- mysummary;', @input_data_1 =N'SELECT *
FROM 
(
    SELECT 
        f.DimArticleId
        , da.ArticleGroupCode
        , dc.NameCze
        , [Value]
    FROM aaa f 
        LEFT OUTER JOIN bbb da
            ON f.Id = da.Id
        LEFT OUTER JOIN ccc dc
            ON f.Id = dc.Id
) AS SourceTable
PIVOT 
    (
        AVG([Value])
        FOR NameCze IN (
                            [Materiál]
                            , [Dílce]
                            , [Kooperace]
                            , [Mzdy]
                            , [Náklady pracovišť]
                            )
    ) AS pvt'; GO

我尝试更改WITH RESULT SETS中的日期类型,但这对我没有帮助。

顺便说一下:aaabbbccc是我的表格的示例。

0 个答案:

没有答案