[R] extracting characteristics of datasets from data()

Michael Friendly friendly at yorku.ca
Mon Oct 25 17:45:13 CEST 2010


I can use data() to find the available datasets in a package, but I'd 
like to extract and display some additional
information for each dataset  than what is provided by data(), e.g., 
class() and dim() for datasets for which
these are available.  I'm stuck on using using lapply properly with 
objects, rather than the names of objects
that I get from data()

Example:

 > DS <- data(package="vcdExtra")
 > DS$results[,c("Item", "Title")]
       Item          Title
  [1,] "Abortion"    "Abortion Opinion Data"
  [2,] "Bartlett"    "Bartlett data on plum root cuttings"
  [3,] "Caesar"      "Risk Factors for Infection in Caesarian Births"
  [4,] "Cancer"      "Survival of Breast Cancer Patients"
  [5,] "Detergent"   "Detergent preference data"
  [6,] "Dyke"        "Sources of knowledge of cancer"
  [7,] "GSS"         "General Social Survey-- Sex and Party affiliation"
  [8,] "Gilby"       "Clothing and Intelligence Rating of Children"
  [9,] "Heart"       "Sex, Occupation and Heart Disease"
[10,] "Heckman"     "Labour Force Participation of Married Women 1967-1971"
[11,] "Hoyt"        "Minnesota High School Graduates"
[12,] "ICU"         "Death in the ICU"
[13,] "JobSat"      "Cross-classification of job satisfaction by income"
[14,] "Mental"      "Mental impariment and parents SES"
[15,] "Mobility"    "Social Mobility data"
[16,] "TV"          "TV Viewing Data"
[17,] "Vietnam"     "Student Opinion About the War in Vietnam"
[18,] "Yamaguchi87" "Occupational Mobility in Three Countries"
 > unlist(lapply(as.list(DS$results[,c("Item") ]), FUN=class))
  [1] "character" "character" "character" "character" "character" 
"character" "character"
  [8] "character" "character" "character" "character" "character" 
"character" "character"
[15] "character" "character" "character" "character"

Wanted: something like the results of doing

 > class(Abortion)
[1] "table"
 > dim(Abortion)
[1] 2 2 2
 > class(Mental)
[1] "data.frame"
 > dim(Mental)
[1] 24  3
 >
for all datasets in Item, giving a display like

Item      class       dim     Title
Abortion  table       2x2x2   Abortion Opinion Data
Mental    data.frame  24x2    Mental impariment and parents SES

-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list