extracting a element with a name attribute from a list

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

extracting a element with a name attribute from a list

Taka Matzmoto
Hi R users

I like to extract (or collect) a numeric element with a name  from a list.

Is there any way to extract just a numeric element without the name attached
to the element.

For example,

>mylist

        Mantel-Haenszel chi-squared test with continuity correction

data:  table(mydata[, x])
Mantel-Haenszel X-squared = 8.3832, df = 1, p-value = 0.003787
alternative hypothesis: true common odds ratio is not equal to 1
95 percent confidence interval:
0.2596963 0.7647255
sample estimates:
common odds ratio
        0.4456415

>is.list(mylist)
[1] TRUE
>names(mylist)
[1] "statistic"   "parameter"   "p.value"     "conf.int"    "estimate"    
"null.value"  "alternative"
[8] "method"      "data.name"
>mylist$estimate
common odds ratio
        0.4456415

I like to extract only a numeric element ( 0.4456415 ) without the name
(common odds ratio).

How can I do that ?

Thanks

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search!


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: extracting a element with a name attribute from a list

Peter Dalgaard
"Taka Matzmoto" <[hidden email]> writes:

> Hi R users
>
> I like to extract (or collect) a numeric element with a name  from a list.
>
> Is there any way to extract just a numeric element without the name
> attached to the element.
>
> For example,
>
> >mylist
>
>         Mantel-Haenszel chi-squared test with continuity correction
>
> data:  table(mydata[, x])
> Mantel-Haenszel X-squared = 8.3832, df = 1, p-value = 0.003787
> alternative hypothesis: true common odds ratio is not equal to 1
> 95 percent confidence interval:
> 0.2596963 0.7647255
> sample estimates:
> common odds ratio
>         0.4456415
>
> >is.list(mylist)
> [1] TRUE
> >names(mylist)
> [1] "statistic"   "parameter"   "p.value"     "conf.int"    "estimate"
> "null.value"  "alternative"
> [8] "method"      "data.name"
> >mylist$estimate
> common odds ratio
>         0.4456415
>
> I like to extract only a numeric element ( 0.4456415 ) without the
> name (common odds ratio).
>
> How can I do that ?

x <- mylist$estimate
names(x) <- NULL

or

x <- as.vector(mylist$estimate)

--
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html