Expand Grid using the name of vector

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Expand Grid using the name of vector

qillbel
I have a problem to append something into a list. I have 5 vectors as follow:
parent<-c("proc1", "proc2")
child<-c("stor1")


and the last 3 vectors were created with looping:
proc1<-c("proc1L", "proc1H")
proc2<-c("proc2L", "proc2H")
stor1<-c("stor1L", "stor1H")


My question is, how can I produce combinatorial elements as shown below with expand.grid(), based on the information on vector parent and child only:
    Var1   Var2   Var3
1 proc1L proc2L stor1L
2 proc1H proc2L stor1L
3 proc1L proc2H stor1L
4 proc1H proc2H stor1L
5 proc1L proc2L stor1H
6 proc1H proc2L stor1H
7 proc1L proc2H stor1H
8 proc1H proc2H stor1H


I tried to do something like this, but it didn't work.
grid_vector<-list()
grid_vector<-append(grid_vector, parent)
grid_vector<-append(grid_vector, child)
expand.grid(grid_vector)

I also looked at http://r.789695.n4.nabble.com/problem-passing-string-as-argument-to-expand-grid-td4655726.html, but with no luck.

Thank you very much for any help

qill
Reply | Threaded
Open this post in threaded view
|

Re: Expand Grid using the name of vector

qillbel
found it
grid_vector<-vector('list')
grid_vector<-append(grid_vector,list(get(paste(child[u],sep=""))))