[R] Is there a way to have 'comment' keep a list?
Keith Jewell
k.jewell at campden.co.uk
Tue Nov 9 12:18:07 CET 2010
I hadn't seen 'comment' before, so don't take my suggestion as
authoritative. It looks useful, so I investigated a bit.
This technique seems to work and is (perhaps?) easier than names:
tlist <- list(a=c(1:3), b=7)
comment(x) <- unlist(sapply(tlist, as.character))
or in one line
comment(x) <- unlist(sapply(list(a=c(1:3), b=7), as.character))
If at least one of the list elements is already character you could simplify
to:
tlist <- list(a=c(1:3), b="fred")
comment(x) <- unlist(tlist)
or in one line
comment(x) <- unlist(list(a=c(1:3), b="fred"))
Not as nice as having a _real_ list, but I guess that would really be a case
for attributes
HTH
Keith J
"Tal Galili" <tal.galili at gmail.com> wrote in message
news:AANLkTimpMMa9_h1+=Oj1BHRf27rLp2J5VeoDHJxQpNxd at mail.gmail.com...
> Hello all,
>
> I recently discovered the "comment" command.
> I see it can only hold a vector of characters.
>
> Is there a way (or an alternative), to make it possible to have it keep a
> list?
> (for example, to keep different pieces of information like date of
> creation,
> information of each variable and so on)
>
> The closest solution I can think of is using 'names' on the vector, like
> this:
> x <- 1
> comment(x) <- letters
> names(comment(x)) <- LETTERS
> x
> comment(x)
>
>
> Any other suggestions?
> (or general best practices for the "comment" command ?)
>
> Thanks,
> Tal
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: Tal.Galili at gmail.com | 972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ----------------------------------------------------------------------------------------------
>
> [[alternative HTML version deleted]]
>
More information about the R-help
mailing list