我正在按照本教程将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