I have a list 'ans' from the following code: tt <- rnorm(50) rr <- rnorm(50) ans <- lm(rr~tt) ans[1] is "$coefficients", ans[2] is "$residuals", ans[3] is "$effects", ... and so on up to ans[12]. Is there an easy way to display just these names and not the data they contain? I thought I saw my advisor type "ans$" and they were displayed, but when I tried it, it just goes to the next line waiting for input like this:> ans$+ I know the answer is really simple, but I can't find it. Thanks! Tina
Try names(ans) Hope this helps, Michael Weylandt On Fri, Sep 9, 2011 at 10:01 AM, Clemontina Alexander <ckalexa2@ncsu.edu>wrote:> I have a list 'ans' from the following code: > > tt <- rnorm(50) > rr <- rnorm(50) > ans <- lm(rr~tt) > > ans[1] is "$coefficients", ans[2] is "$residuals", ans[3] is > "$effects", ... and so on up to ans[12]. Is there an easy way to > display just these names and not the data they contain? I thought I > saw my advisor type "ans$" and they were displayed, but when I tried > it, it just goes to the next line waiting for input like this: > > > ans$ > + > > I know the answer is really simple, but I can't find it. > Thanks! > Tina > > ______________________________________________ > 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]]
Try> names(ans)[1] "coefficients" "residuals" "effects" "rank" [5] "fitted.values" "assign" "qr" "df.residual" [9] "xlevels" "call" "terms" "model" HTH, Jorge * * On Fri, Sep 9, 2011 at 11:01 AM, Clemontina Alexander <> wrote:> I have a list 'ans' from the following code: > > tt <- rnorm(50) > rr <- rnorm(50) > ans <- lm(rr~tt) > > ans[1] is "$coefficients", ans[2] is "$residuals", ans[3] is > "$effects", ... and so on up to ans[12]. Is there an easy way to > display just these names and not the data they contain? I thought I > saw my advisor type "ans$" and they were displayed, but when I tried > it, it just goes to the next line waiting for input like this: > > > ans$ > + > > I know the answer is really simple, but I can't find it. > Thanks! > Tina > > ______________________________________________ > 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]]
> names(ans)[1] "coefficients" "residuals" "effects" "rank" [5] "fitted.values" "assign" "qr" "df.residual" [9] "xlevels" "call" "terms" "model" And thank you for providing a simple reproducible example. Sarah On Fri, Sep 9, 2011 at 11:01 AM, Clemontina Alexander <ckalexa2 at ncsu.edu> wrote:> I have a list 'ans' from the following code: > > tt <- rnorm(50) > rr <- rnorm(50) > ans <- lm(rr~tt) > > ans[1] is "$coefficients", ans[2] is "$residuals", ans[3] is > "$effects", ... and so on up to ans[12]. Is there an easy way to > display just these names and not the data they contain? I thought I > saw my advisor type "ans$" and they were displayed, but when I tried > it, it just goes to the next line waiting for input like this: > >> ans$ > + > > I know the answer is really simple, but I can't find it. > Thanks! > Tina-- Sarah Goslee http://www.functionaldiversity.org
Hi Clemontina, On Fri, Sep 9, 2011 at 11:01 AM, Clemontina Alexander <ckalexa2 at ncsu.edu> wrote:> I have a list 'ans' from the following code: > > tt <- rnorm(50) > rr <- rnorm(50) > ans <- lm(rr~tt) > > ans[1] is "$coefficients", ans[2] is "$residuals", ans[3] is > "$effects", ... and so on up to ans[12]. Is there an easy way to > display just these names and not the data they contain?In this case, you can simply do: R> names(ans) [1] "coefficients" "residuals" "effects" "rank" [5] "fitted.values" "assign" "qr" "df.residual" [9] "xlevels" "call" "terms" "model"> saw my advisor type "ans$" and they were displayed, but when I tried > it, it just goes to the next line waiting for input like this: > >> ans$If you are in the R prompt and you hit <tab> twice after `ans$`, it should show you the names of the elements in the `ans` list. If you use Rstudio[1], the doube <tab> hit will give you a handy dropdown menu list you can choose from. HTH, -steve [1] For what it's worth, I'm not sure how far along in your R-learning you are, but if I were starting out learning R today, I might pick Rstudio as my IDE/interface of choice. -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact