This project has moved and is read-only. For the latest updates, please go here.

results for metric

Dec 19, 2013 at 8:45 PM
Brand new to R and the integration with MicroStrategy. I successfully got my first metric that processes an R script to run. I kept it simple, just having the script generate the mean based on one input.

Is it expected that the resulting grid, which contains 15 rows, will only show the mean in one row and that the calculation of the mean is done using all of the input (Efficiency) data? I suppose I thought that I'd see the mean in every row.

Lastly, note that there are two attributes in the report: one displaying three distinct operations and one displaying a set of five unique weeks (hence, 15 rows). How would I configure the script to display the means within each operational group? For instance, the mean of the first five rows would be displayed in the first five rows of the R script metric, the mean of the second five rows in the second five rows, etc. Is this possible?

Brian
mstr.ErrMsg <- tryCatch({                   #tryCatch error handler

if(exists("mstr.ExFlag")){                  #if executed in MSTR
  df <- data.frame(cbind(Efficiency))           #create data frame
  if(length(mstr.InputNames) > 0) {
    colnames(df) <- mstr.InputNames
  }
} else {                                #if executed from R Console (testing only)
  Efficiency <- seq(1:30)
  #Efficiency <- rnorm(30, m=.96,sd=.1)           #set Efficiency variable
  df <- data.frame(cbind(Efficiency))           #create data frame
  modelName <- "Efficiency Mean"                #set the model name
}
 testmean <- mean(Efficiency, trim=0, na.rm=TRUE)       #get mean
 save(list=c("df", "testmean"), 
    file=paste(modelName, ".Rdata", sep=""))        #persist objects

mstr.ErrMsg <- ""                           #no errors
}, error = function(err) {                  #catch error
  try(print(err))                           #print error
  return(err$message)                       #return error
})
Jan 7, 2014 at 9:38 PM
Your output "testmean" is a scalar, so only a single value will be returned. This would make sense if you defined the analytic signature to have the output testmean as a scalar, and the function will be RScriptAgg since it aggregates your vector inputs. On the other hand, if you defined the output as a vector and you want the value repeated for each row, you should change the output to return a vector of the proper length, such as:

testmean <- mean(Efficiency, trim=0, na.rm=TRUE) #get mean -- returns a scalar
testmean <- rep(testmean, length(Efficiency)) #returns a vector

Hope this helps,

Rick
Jan 8, 2014 at 2:46 PM
Excellent. Thanks for the reply and help.