Christian Langkamp
2009-Feb-04 17:07 UTC
[R] Extracting Variable Name to define breaks for histogram
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) } -- View this message in context: http://www.nabble.com/Extracting-Variable-Name-to-define-breaks-for-histogram-tp21834903p21834903.html Sent from the R help mailing list archive at Nabble.com.
Uwe Ligges
2009-Feb-04 19:03 UTC
[R] Extracting Variable Name to define breaks for histogram
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