gpt4 book ai didi

r - 如何将 R 数据框导出到 Power Query 表

转载 作者:行者123 更新时间:2023-12-04 12:44:42 26 4
gpt4 key购买 nike

我在 Power Query 中使用 R 脚本来执行一些数据转换并返回一个缩放表。
我的R代码是这样的:

# 'dataset' 

最佳答案

这似乎没有返回似乎很奇怪。在线快速浏览给 this 3 minute youtube video ,它使用与您正在使用的方法相同的方法。进一步搜索来源,可能会遇到 Microsoft Documentation ,这给出了可能存在问题的可能原因。

When preparing and running an R script in Power BI Desktop, there are a few limitations:

  • Only data frames are imported, so make sure the data you want to import to Power BI is represented in a data frame

  • Columns that are typed as Complex and Vector are not imported, and are replaced with error values in the created table


这些似乎是最明显的原因。打赌你的数据集中没有复杂的列,我相信先验可能是原因。快速重建您的数据集显示 scale函数将您的数据集更改为 matrix类对象。这是由 cbind 保留的,因此输出属于 matrix 类而不是 data.frame .
>dataset <- as.data.frame(abs(matrix(rnorm(1000),ncol=4)))
>class(dataset)
[1]"data.frame"
>library(dplyr)
>df_normal <- log(dataset + 1) %>%
> select(c(2:4)) %>%
> scale
>class(df_normal)
[1] "matrix"
>df_normal <- cbind(dataset[,1], df_normal)
>output <- df_normal
>class(output)
[1] "matrix"
然后一个简单的修复似乎是添加 output <- as.data.frame(output) ,因为这符合 powerBI 的文档。也许它需要一个 return就像最后的声明。在脚本末尾添加一行简单地说明 output应该解决这个问题。
编辑
为了澄清起见,我相信以下编辑过的脚本(你的)应该返回预期的数据
# 'dataset' contém os dados de entrada neste script

library(dplyr)

df_normal <- log(dataset+1) %>%
select(c(2:4)) %>%
scale
df_normal <-cbind(dataset[,c(1)], df_normal)
output <- as.data.frame(df_normal)
#output ##This line might be needed without the first comment

关于r - 如何将 R 数据框导出到 Power Query 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56046725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com