[R] c() question
Eric Lecoutre
lecoutre at stat.ucl.ac.be
Mon Mar 29 12:19:14 CEST 2004
Hi,
Try to assign the names to your vector after having created it.
It works and it will also simplify your code.
Eric
my.group <- c("one group", "other group")
class.weight <- c(1,2)
my.order <- c(2,1)
my.vector <- class.weight[my.order]
names(my.vector) <- my.group
> my.vector
one group other group
2 1
At 10:58 29/03/2004, Christoph Lehmann wrote:
>Hi
>
>I need to define the following
>
> c("one group" = class.weight[2], "other group" = class.weight[1])
>#class.weight = c(1,2)
>
>but I don't like the hard-coded way and would like to use
>
> my.group <- array(c("one group", "other group"))
>
>but now
>
> c(my.group[1] = class.weight[2], my.group[2] = class.weight[1])
>
>gives an error
>
>how can I solve this small problem?
>
>thanks for a hint
>
>christoph
>
>--
>Christoph Lehmann <christoph.lehmann at gmx.ch>
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Eric Lecoutre
UCL / Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium
tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre
If the statistics are boring, then you've got the wrong numbers. -Edward
Tufte
More information about the R-help
mailing list