[R] The equivalent of which() when accessing slots in an object
Thomas Chesney
Thomas.Chesney at nottingham.ac.uk
Mon Oct 31 15:09:19 CET 2016
I have the following object
setClass("buyer",
representation(
reqstock="numeric",
buyout="numeric"),
)
nBuy <- 5
#Set buyer parameters here
buylist <- list()
for (i in 1:nBuy){
buylist[[i]] <- new("buyer")
buylist[[i]]@reqstock <- sample(c(50:200),1)
}
and want to count the number of objects in buylist that have reqstock greater than 100. Something like this if it was a vector:
length(which(buylist[[]]@reqstock > 100))
How could I do this please and where could I find more information about manipulating slots? When I try to search for this I just keep finding info on ls() and similar functions.
Thank you
Thomas Chesney
http://www.nottingham.ac.uk/~liztc/Personal/index.html
This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it.
Please do not use, copy or disclose the information contained in this
message or in any attachment. Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.
This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.
More information about the R-help
mailing list