[R] help with loops

Srinivas Iyyer srini_iyyer_bio at yahoo.com
Thu Aug 11 18:46:50 CEST 2011


hi I need help with list object. 

I have a list object

> a <- c('apple','orange','grape')
> b <- c('car','truck','jeep')
> c <- list(a,b)
> names(c) <- c('fruit','vehicle')
> c
$fruit
[1] "apple"  "orange" "grape" 

$vehicle
[1] "car"   "truck" "jeep" 


I want to write all the elements of this list in one object 'z'. 

>z
[1] "apple"  "orange" "grape" "car"   "truck" "jeep"

How can I write the elements of c to z
I tried using a for loop. Could any one help me please. thanks


> z <- ''
> for (i in 1:length(c)){
+ k <- c[[i]]
+ z <- c(z,k)
+ return(z)} 
Error: no function to return from, jumping to top level
> 


Thank you. 
srini



More information about the R-help mailing list