====== Symbolic objects in R ====== > setClass("interval",representation(min="numeric",max="numeric")) [1] "interval" > getClass("interval") Class "interval" [in ".GlobalEnv"] Slots: Name: min max Class: numeric numeric > a <- new("interval",min=2,max=3) > a An object of class "interval" Slot "min": [1] 2 Slot "max": [1] 3 > x <- vector("list",2) > x [[1]] NULL [[2]] NULL > T <- data.frame(u=x,v=x) > T data frame with 0 columns and 0 rows > # 17. december 2011 # http://rwiki.sciviews.org/doku.php?id=tips:data-frames:list_in_data.frame > df <- data.frame (normal.column = "a", + the.list = I(list ("1st.row" = list ("x" = 8, "unit" = "mm"), + "2nd.row" = "blabla") )) > df normal.column the.list 1st.row a 8, mm 2nd.row a blabla > > T <- data.frame(u = c(7,4), v = I(list( "prva"=a, "druga"=a ))) > T Error in as.character.default() : no method for coercing this S4 class to a vector > A <- c(4,5,6); B <- c(7,1,3) > T <- data.frame(u = c(7,4), v = I(list(A,B))) > T u v 1 7 4, 5, 6 2 4 7, 1, 3 > T[2,2] [[1]] [1] 7 1 3 > Z <- data.frame(u = c(7,4), v = I(list( "prva"=a, "druga"=a ))) > Z[2,1] [1] 4 > Z[2,2] $druga An object of class "interval" Slot "min": [1] 2 Slot "max": [1] 3 > b <- new("interval",min=5,max=9) > Z[2,2] <- b > Z[2,2] $druga An object of class "interval" Slot "min": [1] 5 Slot "max": [1] 9 > dim(Z) [1] 2 2 ===== Refs ===== * http://blog.datacamp.com/data-table-cheat-sheet/ ; https://github.com/Rdatatable/data.table/wiki ; https://github.com/Rdatatable/data.table/wiki/Articles ; https://s3.amazonaws.com/assets.datacamp.com/img/blog/data+table+cheat+sheet.pdf * http://stat.ethz.ch/R-manual/R-patched/library/base/html/class.html * http://stat.ethz.ch/R-manual/R-devel/library/methods/html/refClass.html * http://stat.stanford.edu/~jmc4/pub.html * http://stat.stanford.edu/~jmc4/classInheritance.pdf * http://www.ibm.com/developerworks/linux/library/l-r3/ * http://www.stat.wisc.edu/~deepayan/SIBS2005/slides/objects.pdf * http://en.wikipedia.org/wiki/Object-oriented_programming * http://www.omegahat.org/ * http://www.uwyo.edu/mdillon/hor.html * http://zoonek2.free.fr/UNIX/48_R/02.html