我有关于各种费用的数据(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
中的日期类型,但这对我没有帮助。
顺便说一下:aaa
,bbb
,ccc
是我的表格的示例。