[R] Interpreting the output of str on a data frame created using aggregate function

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Fri Jan 24 20:03:23 CET 2025


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
(3) Group.1 is a ?list? of number
(4) x which is a 844x7 matrix having value "Good", "Moderate", etc.

A few questions:
(A) Is the interpretation given above correct?
(B) Does the .. ..$ : NULL mean that the matrix has no row names?  
(C) What does "attr(*, "dimnames")=List of 2" mean?
(D) Does it mean that the dimensions of the matrix are stored as two separate lists? 
(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





More information about the R-help mailing list