[R] accessing the attr(*,label.table) after importing from spss

moleps moleps2 at gmail.com
Wed Aug 25 22:26:07 CEST 2010


Dear all,
I just received a file from a colleague in spss. The read.spss could not finish the file due to an error (Unrecognized record type 7, subtype 18 encountered in system file) so instead I converted the file using stat-transfer. Looking at my data I see that most labels are in the attributes and I´d love to access them and assign the pertinent variables to factors without doing the whole factor(levels,labels) thing manually. Is there any remedy to this ??

regards,

M


> str(dat)
'data.frame':	860 obs. of  19 variables:
 $ Ag            : int  15 15 15 15 15 15 15 15 15 15 ...
 $ G        : int  2 2 2 1 1 1 1 1 1 2 ...
 $ GCQ            : int  15 15 15 15 15 15 15 15 15 15 ...
 $ Amn        : int  2 2 2 2 2 2 1 1 1 1 ...
 $ HI          : int  1 1 1 1 1 1 2 2 2 2 ...
 $ Hos: int  2 2 2 2 2 2 2 2 2 2 ...
 $ Risk   : int  2 2 2 2 2 2 2 2 2 2 ...
 $ CTO             : int  2 2 2 2 2 1 1 1 1 1 ...
 $ pat      : int  NA NA NA NA NA 2 2 2 2 2 ...
 $ Day            : int  7 7 7 5 4 6 5 7 7 5 ...
 $ Ho      : int  NA NA NA NA NA NA NA NA NA NA ...
 $ coh      : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Comp     : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Ethan        : int  2 2 2 2 2 2 2 2 2 2 ...
 $ Pro       : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Ye          : int  1 1 1 3 3 3 1 1 1 3 ...
 $ Ageg    : int  1 1 1 1 1 1 1 1 1 1 ...
 $ BAC            : int  0 0 0 0 0 0 0 0 0 0 ...
 - attr(*, "val.labels")= chr  "" "VL_Gender" "" "VL_Amnesia" ...
 - attr(*, "var.labels")= chr  "Age (years)" "Gender" "GCQSSA" "Amnesty" ...
 - attr(*, "label.table")=List of 19
  ..$ : NULL
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Male" "Female"
  ..$ : NULL
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : NULL
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : Named num  1 2 3 4 5 6 7
  .. ..- attr(*, "names")= chr  "Monday" "Tuesday" "Wednesday" "Thursday" ...
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : Named num  1 2 3 4 5 6 7
  .. ..- attr(*, "names")= chr  "Yes" "Overtriage " "Undertriage with admission" "Overtriage with pos" ...
  ..$ : Named num  1 2
  .. ..- attr(*, "names")= chr  "Yes" "No"
  ..$ : NULL
  ..$ : NULL
  ..$ : Named num  1 2 3 4
  .. ..- attr(*, "names")= chr  "15 - 24" "25-39" "40-59" "60-"
  ..$ : Named num  1 2 3
  .. ..- attr(*, "names")= chr  "0.10-0.99" "1.00-1.99" "2.00-"
  ..$ : Named num  0 1 2 3 4
  .. ..- attr(*, "names")= chr  "sorry" "undeweight" "0.10-0.99" "1.00-1.99" ...


More information about the R-help mailing list