Skip to content

Dynamic data.frame headers

2 messages · Mattias Nyström, Hans Gardfjell

#
Hi Mattias,

Try this,

percentiles <- c(0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 0.95, 1.00)
test <-  data.frame(matrix(NA,0,12))
names(test) <- paste("p",percentiles*100,sep="")
 
test
 [1] p5   p10  p20  p30  p40  p50  p60  p70  p80  p90  p95  p100

Cheers, Hans

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Mattias Nystr?m
Sent: Wednesday, January 13, 2010 10:11
To: r-help at r-project.org
Subject: [R] Dynamic data.frame headers

I would like to create a data.frame with dynamic created headers. I will later fill it with percentiles. My percentiles vector is:
percentiles = c(0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 0.95, 1.00)
p5, p10, p20, ..., p95, p100

Is it possible to create headers in such way, something like "p"+100*c?


______________________________________________
R-help at r-project.org 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.