[R] Extracting Variable Name to define breaks for histogram

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Feb 4 20:03:55 CET 2009



Christian Langkamp wrote:
> Hi
> 
> I am trying to define an automatic breaks function for a histogram.
> Inputs are a vector x and a number n. What I would like is to define the
> outcome as breaks_(Name of Vector) - but the paste("breaks_",x) obviously
> refers to the whole vector. 
> 
> breaks<- function(x, n)
> {
> R<-range(x, na.rm=T)
> diff_x<-R[2]-R[1]
> paste("breaks_",x)<-c(NA, seq(floor(R[1]), ceiling(R[2]),diff_x/n))
> rm(diff_x, R)
> }

I do not think you want it that way. You want to return values, not to 
assign it into the environment of a function that is shortly deleted anyway.

Anyway, for the assignment itself (that is also undesirable), see ?assign

Uwe Ligges




More information about the R-help mailing list