Hi:

See inline.

On Mon, Sep 6, 2010 at 9:29 AM, Viki S <isvik@live.com> wrote:

>
> Hi Jim,
> Thanks,
>
> That愀 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 ?
>

Short answer: don't put special characters in your names.
In R, : is a binary operator (sequencing). Moreover,
use data frames when you have variables of mixed type
rather than matrices.

Compare the following:

> d <- data.frame(nm = c("row:1", "row:2", "row:3"),
+                 val = c(4889, 9987, 494))
> d
     nm  val
1 row:1 4889
2 row:2 9987
3 row:3  494
> l <- as.list(d[, 2])
> names(l) <- d$nm
> l
$`row:1`
[1] 4889

$`row:2`
[1] 9987

$`row:3`
[1] 494

> d <- data.frame(nm = c("row1", "row2", "row3"),
+                  val = c(4889, 9987, 494))
> l <- as.list(d[, 2])
> names(l) <- d$nm
> l
$row1
[1] 4889

$row2
[1] 9987

$row3
[1] 494

HTH,
Dennis

V
>
> > Date: Mon, 6 Sep 2010 09:14:23 -0400
> > Subject: Re: [R] Creating named.list from two matrix columns
> > From: jholtman@gmail.com
> > To: isvik@live.com
> > CC: r-help@r-project.org
> >
> > 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 <isvik@live.com> 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]]
> > >
> > > ______________________________________________
> > > R-help@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.
> > >
> >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem that you are trying to solve?
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@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.
>
>

	[[alternative HTML version deleted]]

