Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
kids1 = as.array(c("Bob", "Joe"))
kids2 = as.array(c("Steve", "Beth", "Kim"))
setClass("person", representation(name="character", age="numeric", children = "list"))
setMethod(
f = "[",
signature="person",
definition=function(x,i,j,...,drop=TRUE){
initialize(x, name=x@name[i], age = x@age[i], children = list(x@children[i]))
}
)
people = new("person", name=c("John", "Fred"), age=c(40, 20), children = list(kids1, kids2))
people[1]@name
people[1]@age
people[1]@children
people[2]@name
people[2]@age
people[2]@children
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.