Append Histogram Class Objects to a list elements in R
My title's problem is very similar to a lot of's in SOF, though my problem is very different : I got a list MY_LIST.
I got a histogram class object HIST_OBJECT.
HIST_OBJECT=hist(rnorm(n=500, m=1, sd=1)) class(HIST_OBJECT)  "histogram"
I want to load my HIST_OBJECT into the 1st slot of my list MY_LIST. So i execute that :
So far so good but the problem is that the class of my HIST_OBJECT has changed. It was an histogram class that i could plot (plot(HIST_OBJECT) works!) but now it's a list class that I can't plot anymore (plot(MY_LIST[]) don't work)
class(MY_LIST[])  "list"
Does anyone know how to do in order to make MY_LIST[] object an "histogram" class object? Thanks a lot in advance!!
You were close:
Think of a list like a train: a single [ gets the carriage you want with all its contents, a double [[ gets just the contents of that carriage. Also think why MY_LIST[]=HIST_OBJECT does not work, but MY_LIST[][]=HIST_OBJECT does.
In this case, the  got you the same class as its container - a list, containing the second element, your hist. The [] will get you the element in the second container, in this case your hist.
df <- data.frame(x=c(1,2,3), y=c(4,5,6)) class(df) class(df[])