0

How can i transform getter values to data frame for example :

I have a simple class (person) and it has 2 objects (name and person),if i would like to get age values, i have to do run this simple instruction "person["age"]" and i get this result

    An object of class "person"
    Slot "val":
    [1] 20 22 15 22 16

How can i transform it into data frame :

     age 
     20
     22
     15  
     22
     16

Thank you

this is dput result (forget about the other class ,person and human were just examples !)

     new("Data"
, X = new("Signal"
, val = c(21, 22, 21, 22, 22, 24, 22, 23, 22, 22, 21)
)
, Y = new("Signal"
, val = c(11, 14, 13, 12, 12, 13, 12, 13, 14, 13, 13)
)
, Z = new("Signal"
  , val = c(-130, -128, -129, -129, -129, -127, -128, -128, -128, -129, 
  -130)
 )

 )

this is setclass

 .Signal.valid <- function(object){ return(TRUE)}
   setClass (
   Class ="Signal",
   representation= representation(val="numeric"),
   validity =.Signal.valid
   )
   rm (.Signal.valid )
joran
  • 169,992
  • 32
  • 429
  • 468
foboss
  • 430
  • 4
  • 14

1 Answers1

0

I'm not sure if your class structure is the same as mine, but I'll give it a shot:

setClass("Signal", representation(val = "numeric"))
setClass("Data", representation(X = "Signal", Y = "Signal", Z = "Signal"))
obj <- new("Data", X = new("Signal", val = c(21, 22, 21, 22, 22, 24, 22, 23, 22, 22, 21)), 
                   Y = new("Signal", val = c(11, 14, 13, 12, 12, 13, 12, 13, 14, 13, 13)), 
                   Z = new("Signal", val = c(-130, -128, -129, -129, -129, -127, -128, -128, -128, -129, -130)))

data.frame(obj@X@val, obj@Y@val, obj@Z@val)

   obj.X.val obj.Y.val obj.Z.val
1         21        11      -130
2         22        14      -128
3         21        13      -129
4         22        12      -129
5         22        12      -129
6         24        13      -127
7         22        12      -128
8         23        13      -128
9         22        14      -128
10        22        13      -129
11        21        13      -130

Is that what you are trying to achieve?

tonytonov
  • 25,060
  • 16
  • 82
  • 98