Hi Jim,
Thanks,
That´s right. But the problem is that it
introduces unnecessary quotes, perhaps due to the format of first
column data in this case :
x<-cbind(c("row:1", "row:2", "row:3"), c("4889", "9987", "494"))
x1<-as.list(x[,2])
names(x1)<-x[,1]
> x1
$`row:1`
[1] "4889"
$`row:2`
[1] "9987"
$`row:3`
[1] "494"
How can I avoid unnecessary ` `quotes around the names ?
V
> Date: Mon, 6 Sep 2010 09:14:23 -0400
> Subject: Re: [R] Creating named.list from two matrix columns
> From: [email protected]
> To: [email protected]
> CC: [email protected]
>
> Is this what you want:
>
> > x
> V1 V2
> 1 row1 2334
> 2 row2 347
> 3 row3 379
> > x.list <- as.list(x$V2)
> > names(x.list) <- x$V1
> > x.list
> $row1
> [1] 2334
>
> $row2
> [1] 347
>
> $row3
> [1] 379
>
>
>
> On Mon, Sep 6, 2010 at 7:55 AM, Viki S <[email protected]> wrote:
> >
> > Hi Friends,
> > I am new to R.
> >
> > On R utility class pages, creating "named.list" is described with this
> > command :
> > new("named.list",a=1,b=2)
> >
> >
> > For large matrix having two columns, such as :
> >
> > "row1" 2334
> > "row2" 347
> > "row3" 379
> > ...
> >
> > I want to create a named.list like :
> > $row1
> > [1] 2334
> >
> > $row2
> > [1] 347
> >
> > ...
> >
> > Can anyone explain how "named.list" variable can be created by using two
> > specified columns of a dataframe or matrix object, where one of the two
> > columns is assigned as a name (string) and
> > other as its corresponding value ?
> >
> > Thanks
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [email protected] 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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.