[R] how to get R interpreter to remember constant values without using any memory location

Ben Bolker bolker at ufl.edu
Thu Aug 13 20:25:43 CEST 2009




mauede wrote:
> 
> Maybe I expect too much from a non compiled language.
> Anyway, I wonder whether it is possible in R to set constant values
> without using any memory location that would take useless space 
> bacause such values are not going to be changed along the program. It's
> just a way to assign a mnemnic name tos some constant values.
> For instance, I would like R interpreter to replace all occurrences of
> mnemonic "Monday" with the number 1, "Tuesday"  with the number 2,
> "Wednesday  with the number 3, and so on ...  without having to assign
> such values to memory locations.
> Maybe environment variables are the way to go ?  
> 
> 

  It would help if you were a little bit more specific about what you wanted
to do and why.
My initial reaction is that this is exactly the thing that the "factor"
class in R is designed
to do -- maintain a list of unique names corresponding to integer codes, and
handle
them (almost) transparently.  (There are a few tricky aspects to dealing
safely/correctly
with factor conversions: see
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors )

  Ben Bolker
-- 
View this message in context: http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956333.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list