Product: TIBCO Spotfire®
Change the class() of a Spotfire S+ object
User has a set of objects and would like to subdivide them into different classes so that he can apply different methods to each class.
You can achieve this class change by using the new() function in Spotfire S+. Here is an example of changing a data.frame object to a new class called "Alg".
##########################
# Create your new class
> setClass("Alg", representation(x="data.frame"))
> getClass("Alg")
Slots:
x
"data.frame"
# Create a data.frame object
ngs <- data.frame(a=letters[1:5], b=rnorm(5))
> ngs
a b
1 a 0.2036561
2 b 1.9164974
3 c 0.7680376
4 d -1.2622936
5 e 0.5144450
# Confirm the class
> class(ngs)
[1] "data.frame"
# Write a simple function to change the class
dfToAlg <- function(object) {new("Alg", x=object)}
# Run the function on your object
# Be sure to assign it back to your original object
ngs <- dfToAlg(ngs)
> ngs
a b
1 a 0.2036561
2 b 1.9164974
3 c 0.7680376
4 d -1.2622936
5 e 0.5144450
# Confirm the class change
> class(ngs)
[1] "Alg"
###################
Comments
0 comments
Article is closed for comments.