r - PowerBI中意外的R程序(正则表达式)输出
问题描述
我正在按照本教程将 R 合并到 Microsoft PowerBI,http: //radacad.com/power-bi-and-regular-expressions
使用我自己的数据
我明白如何
# '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)}
output <- within(dataset,{Building=isValid(dataset$GROUP_NAME)})
翻译成这个
但是我如何打印出匹配的字符串本身,即02M477
,08X048
等
我试过了
# 'dataset' holds the input data for this script
pattern <- "[[:digit:]]{2}[[:alpha:]]{1}[[:digit:]]{3}"
isValid <- function(x) {grep(pattern , as.character(x), ignore.case=TRUE, value=TRUE)}
output <- within(dataset,{Building=isValid(dataset$GROUP_NAME)})
我期待
然而我得到以下错误......如何解决?
DataSource.Error: ADO.NET: R script error.
Error in `[<-.data.frame`(`*tmp*`, nl, value = list(Building = c("Madison\\Manual\\02M477-Shift Stick", :
replacement element 1 has 760 rows, need 768
Calls: within -> within.data.frame -> [<- -> [<-.data.frame
Execution halted
Details:
DataSourceKind=R
DataSourcePath=R
Message=R script error.
Error in `[<-.data.frame`(`*tmp*`, nl, value = list(Building = c("Madison\\Manual\\02M477-Shift Stick", :
replacement element 1 has 760 rows, need 768
Calls: within -> within.data.frame -> [<- -> [<-.data.frame
Execution halted
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException
解决方案
这应该在 r
regmatches(string, regexpr(pattern, string))
推荐阅读
- javascript - 用 'e' Jquery 连接字符串
- java - 在解决有关 Java 中的语句和表达式的问题时遇到问题(语句 x = y = x = 0 是非法的??)
- python - 如何计算从年、月、周的乞讨到现在已经过去了多少天?
- python - 如何解决“打破外部循环”?
- macros - 将宏变量传递给函数进行插值
- javascript - 如何在更改 Web 开发的屏幕尺寸时裁剪图像
- java - 试图让字符串在新文件中打印
- c++ - 不使用左右停止工作命名空间std的简单比较
- python - 使用 numpy 初始化系列对象?
- python - 在 Google Colab 中将导入的 csv 文件作为 pandas DataFrame 的错误消息