Re: [R] use variable value as vector name

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Wed, 09 Jul 2008 17:44:49 -0500

a <- "apple"
b <- "pear"
c <- "banana"

result <- c(2, 3, 5)
names(result) <- c(a, b, c)

Qian R wrote:
> Here is my problem
>
> a <- data$name[1]
> b <- data$name[2]
> c <- data$name[3]
>
> a
> "apple"
> b
> "pear"
> c
> "banana"
>
> result <- c( a = 2 , b=3, c=5)
>
> output:
> a b c
> 2 3 5
>
> But I want my output
> apple pear banana
> 2 3 5
>
>
>
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> 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.



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. Received on Wed 09 Jul 2008 - 22:48:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jul 2008 - 23:31:42 GMT.

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

list of date sections of archive