Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use R attributes to save physical units?

Can I (should I) use R attributes to save physical units and similar information as hint for the user?

epsilon0 <- 8.854188e-12
# name <- "electric constant"
# source <- "CODATA"
# unit <- "F m-1"
like image 493
Jonas Stein Avatar asked Nov 26 '12 02:11

Jonas Stein


2 Answers

You can, with this code:

attributes(epsilon0) <- list(name = "electric constant", source = "CODATA", unit="F m-1")
like image 137
Matthew Lundberg Avatar answered Sep 28 '22 15:09

Matthew Lundberg


In addition to @MatthewLundberg's answer, you can set and get individual attributes like:

> attr(epsilon0,"name") <- "electric constant"
> epsilon0
[1] 8.854188e-12
attr(,"name")
[1] "electric constant"


> attr(epsilon0,"name")
[1] "electric constant"
like image 35
thelatemail Avatar answered Sep 28 '22 16:09

thelatemail