[R] Interpreting the output of str on a data frame created using aggregate function
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Fri Jan 24 20:13:47 CET 2025
I'll answer your question inline.
On 2025-01-24 2:03 p.m., Sorkin, John wrote:
> I ran the following code:
> marginalcats <- aggregate(meanbyCensusIDAndDay3$cats,
> list(meanbyCensusIDAndDay3$CensusID),table)
> followed by
> str(marginalcats)
>
> I received the following output:
> 'data.frame': 844 obs. of 2 variables:
> $ Group.1: num 6e+09 6e+09 6e+09 6e+09 6e+09 ...
> $ x : int [1:844, 1:7] 14 14 14 14 14 14 14 14 14 14 ...
> ..- attr(*, "dimnames")=List of 2
> .. ..$ : NULL
> .. ..$ : chr [1:7] "Good" "Moderate" "Unhealthy For Some" "Unhealthy" ...
>
> I am trying to understand the output. I believe it says that marginalcats
> (1) is a data frame
> (2) the df has two elements (I) Group.1 and (II) x
Correct so far.
> (3) Group.1 is a ?list? of number
No, it's a numeric vector. The length doesn't print because it's in a
dataframe, so the length is 844, the number of dataframe observations.
> (4) x which is a 844x7 matrix having value "Good", "Moderate", etc.
Correct.
>
> A few questions:
> (A) Is the interpretation given above correct?
> (B) Does the .. ..$ : NULL mean that the matrix has no row names?
Yes.
> (C) What does "attr(*, "dimnames")=List of 2" mean?
That says x has an attribute called "dimnames", which is a list with two
elements. They are the row names (which is NULL, you don't have any)
and the column names.
> (D) Does it mean that the dimensions of the matrix are stored as two separate lists?
No. The dim is an attribute which is shown implicitly as "[1:844,
1:7]", i.e. c(844, 7).
Duncan Murdoch
> (E) If so, how do I access the lists?
> When I enter
> dimnames(marginalcatsx$x)
> I receive:
>
> [[1]]
> NULL
>
> [[2]]
> [1] "Good" "Moderate" "Unhealthy For Some" "Unhealthy" "Very Unhealthy" "Hazardous1"
> [7] "Hazardous2"
>
> Thank you,
> John
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine, University of Maryland School of Medicine;
> Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center Geriatrics Research, Education, and Clinical Center;
> PI Biostatistics and Informatics Core, University of Maryland School of Medicine Claude D. Pepper Older Americans Independence Center;
> Senior Statistician University of Maryland Center for Vascular Research;
>
> Division of Gerontology and Paliative Care,
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> Cell phone 443-418-5382
>
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list