Last active
August 29, 2015 14:08
-
-
Save datalove/76d52a561402e9a9c213 to your computer and use it in GitHub Desktop.
TERR Script to be used in a Spotfire 'Expression Function'0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################################### | |
# | |
# Expression Functions in Spotfire can take arbitrarily | |
# many columns as input. Columns will be passed to TERR | |
# in order as 'input1', 'input2', etc. | |
# | |
# This shows how to capture an arbitrary number of | |
# columns and to put them into a data frame. | |
# | |
####################################################### | |
inputs <- grep("^input[0-9]+$",ls(), value = TRUE) | |
# capture columns as a matrix | |
my.matrix <- sapply(inputs, function(x) {eval(parse(text = x))}) | |
# capture columns as a data frame | |
my.df <- as.data.frame(sapply(inputs, function(x) {eval(parse(text = x))})) | |
# Now do something with the matrix or dataframe that evaluates | |
# to a vector of length equal to the number of rows in the table | |
# i.e. length(input1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment