Skip to content

ls() pattern

2 messages · livia, Moshe Olshansky

#
Hello everyone,

I get some data in the following format and I would like to combine them to
form a dataframe. 

The data is like:

cbcname1 = 0.1,
cbcname2= 0.2,
cbcname3=0.3,...

name1, name2, name2 are just some random names. I would like to achieve sth
like:
(cbcname1=0.1, cbcname2=0.2, cbcname3=0.3,......)

I am using the following codes
do.call(cbind, ls(pat=paste("cbc",*,"=")))

But it seems like the ls() part does not work. 

Could anyone give me some advice? Many thanks.
#
Hi Livia,

Below is my solution. I believe that other list
members will post a better one.

Regards,

Moshe.
eval(parse(text=paste(paste("x",1:5,sep=""),paste("<-1.",1:5,";",sep=""))))
eval(parse(text=paste(paste("y",1:5,sep=""),paste("<-2.",1:5,";",sep=""))))
eval(parse(text=paste(paste("xy",1:5,sep=""),paste("<-12.",1:5,";",sep=""))))
[1] "x1"  "x2"  "x3"  "x4"  "x5"  "xy1" "xy2" "xy3"
"xy4" "xy5" "y1"  "y2"  "y3"  "y4"  "y5"
[1] "xy1" "xy2" "xy3" "xy4" "xy5"
paste("df<-data.frame(",paste(a,"=",a,",",sep="",collapse=""),")",sep="")
[1]
"df<-data.frame(xy1=xy1,xy2=xy2,xy3=xy3,xy4=xy4,xy5=xy5,)"
[1]
"df<-data.frame(xy1=xy1,xy2=xy2,xy3=xy3,xy4=xy4,xy5=xy5
)"
xy1  xy2  xy3  xy4  xy5
1 12.1 12.2 12.3 12.4 12.5

        
--- livia <yn19832 at msn.com> wrote:

            
http://www.nabble.com/ls%28%29-pattern-tp14316765p14316765.html