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>
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
Christoph, yes there IS a way, such as the horrible
eval(parse(text=paste("c(", my.group[1],
" = ", class.weight[2], ",", my.group[2], " = ",
class.weight[1], ")", sep="")))
BUT I would suggest you rethink whether there isn't a an altogether
more straightforward way to do what you want. For example,
tmp <- class.weight
names(tmp) <- my.group
HTH
> -----Original Message-----
> From: Christoph Lehmann [mailto:christoph.lehmann at gmx.ch]
> Sent: 29 March 2004 09:58
> To: r-help at stat.math.ethz.ch
> Subject: [R] c() question
>
>
> Security Warning:
> If you are not sure an attachment is safe to open contact
> Andy on x234.
> There are 0 attachments with this message.
> ________________________________________________________________
>
> 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
>
Simon Fear
Senior Statistician
Syne qua non Ltd
Tel: +44 (0) 1379 644449
Fax: +44 (0) 1379 644445
email: Simon.Fear at synequanon.com
web: http://www.synequanon.com
Number of attachments included with this message: 0
This message (and any associated files) is confidential and\...{{dropped}}