[R] use variable value as vector name

Erik Iverson iverson at biostat.wisc.edu
Thu Jul 10 00:44:49 CEST 2008


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.



More information about the R-help mailing list