Jump to content

I have a column with integers and i wish to have calculated column to sort the integer from BIG to SMALL...and always have 4 digits...anyone can help?


Chee Kheong Wan

Recommended Posts

I cannot see a way of doing it with a simple Spotfire expression. I would suggest to create the new column using a TERR expression function.

To create it, go to menu > Data > Data Function Properties > Expression Functions tab.

Then choose New.. and add a Column Function with return type Integer and category Statistical Function, using the following script:

sort4digits = function(v) { vi=strsplit(as.character(v),'')[[1]] vi=sort(vi,decreasing=TRUE) vi=c(vi,rep(0,4-length(vi))) vi=as.integer(paste(vi,collapse='')) return (vi)} output = sapply(input1,sort4digits)

The sort4digits function takes each integer, e.g. 6329, splits it into a vector, sorts the vector highest first, pads it with zeroes if shorter than 4, then re-collapses the four digits into an integer. Then the output column is created by applying this function to all rows.

Call this expression function e.g. TERR_sortMe.

Then create your new column as the following expression:

TERR_sortMe([value])

where [value] will be your original column.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...