r - 如何在 PowerBI 中过滤 R 表达式
问题描述
软件: PowerBI(在https://powerbi.microsoft.com/en-us/downloads/免费下载)
R版本: R-3.5.3
这是我正在关注的过程的动画 Gif
我正在尝试在 R 代码中进行过滤
这是我的数据
GROUP_NAME
Madison\Manual\02M477-Shift Stick
Unknown
Barbie\Instant\08X048
Earrings\Instant\30Q739
Barbie\Instant\08X130
Earrings\Instant\26Q430
我希望它看起来像这样
我尝试添加布尔变量isValid
(如果匹配正则表达式则为 TRUE,否则为 FALSE)
然后我尝试isValid
在添加到数据集(填充新列 Building)之前进行评估
如果isValid
为 TRUE,则输出 digit-digit-letter-digit-digit-digit
否则,如果isValid
为 FALSE,则输出“”
# 'dataset' holds the input data for this script
pattern <- "[[:digit:]]{2}[[:alpha:]]{1}[[:digit:]]{3}"
isValid <- function(x) {grepl(pattern , as.character(x), ignore.case=TRUE)}
bldgCode <- function(x) {grep(pattern , as.character(x), ignore.case=TRUE, value=TRUE)}
output <- within(dataset,{if (isValid==TRUE){Building=bldgCode(dataset$GROUP_NAME)} else " "})
相反,我得到错误,请协助
DataSource.Error: ADO.NET: R script error.
Error in isValid == TRUE :
comparison (1) is possible only for atomic and list types
Calls: within -> within.data.frame -> eval -> eval
Execution halted
Details:
DataSourceKind=R
DataSourcePath=R
Message=R script error.
Error in isValid == TRUE :
comparison (1) is possible only for atomic and list types
Calls: within -> within.data.frame -> eval -> eval
Execution halted
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException
解决方案
推荐阅读
- c++ - 在 macOS Catalina 上链接 OpenMP 时出现“未定义符号 _main”
- azure-storage - 通过浏览器访问 Azure 存储帐户容器 - 出现身份验证错误
- javascript - 如何将函数从 forEach() 更改为使用一个元素 JS 的函数
- javascript - 在 Django 框架中正确加载 jquery 和扩展 base.html 模板的使用
- c - 处理 C 中大于 ULONG_MAX 的数字
- ios - 将 swift Xcode 项目转换为可导入的 cocoapods
- excel - 如何创建具有多个 OR 条件的 if 语句?
- javascript - 程序不输出到控制台
- android - 如何检测对安卓智能手表屏幕的长按?
- javascript - 如何显示用户使用Vue JS输入的信息的预览?