Re: [R] prefixing list names in print

From: bogdan romocea <br44114_at_gmail.com>
Date: Wed 09 Aug 2006 - 06:27:05 EST


A simple function will do what you want, customize this as needed: lprint <- function(lst,prefix)
{
for (i in 1:length(lst)) {

   cat(paste(prefix,"$",names(lst)[i],sep=""),"\n")    print(lst[[i]])
   cat("\n")
}
}
P <- list(A="a",B="b")
lprint(P,"Prefix")

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Laurent Deniau
> Sent: Tuesday, August 08, 2006 12:25 PM
> To: R-help
> Subject: [R] prefixing list names in print
>
> With
>
> print(list(A="a",B="b"))
>
> it displays
>
> $A
> [1] "a"
>
> $B
> [1] "b"
>
> I would like to add a common prefix to all the list tags after the $.
> Pasting the prefix to the "names" does not work (appear after the $).
> For example if the prefix would be "P", it should display:
>
> P$A
> [1] "a"
>
> P$B
> [1] "b"
>
> I tried to add a "name" attribute to the list or to add a
> prefix="P" to
> print but nothing works. Any hint?
>
> Thanks,
>
> Laurent.
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed Aug 09 06:33:01 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 09 Aug 2006 - 20:22:51 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.