[R] What's a labelled data.frame? And how do I work with it?

John Kane jrkrideau at yahoo.ca
Tue Aug 1 21:48:27 CEST 2006


--- John Kane <jrkrideau at yahoo.ca> wrote:

> I imported an SPSS file with its data labels using
> spss.get (Library(Hmisc).
> Class = data.frame
> 
> I then updated some of the spss labels and added a
> label to the object itself.
> 
> label (staff.allocation) <- "raw data from the spss
> file"
> 
>  I then save it as an R object. When I load the
> object
> for further work it comes in as Class =  "labelled"
> "data.frame"
>  
> 
>  Then I try this
> 
>
---------------------------------------------------------
>  # Get the raw data that we have imported from SPSS.
> load("H:/R.objects/staff.allocation.Rdata")
> 
> # Recode all 99's in the data base as NA except
> dates
> and Subject since subject
> # 99 is a valid ID number.
> 
> # Drop dates and ids
> st1 <- staff.allocation[, -1:-4]
> 
>  st1[st1==99] <- NA
> 
> #replace date and id forget the entry date
> st2 <-data.frame(staff.allocation$site,
> staff.allocation$subject,
>           staff.allocation$date, st1)
> 
>
-----------------------------------------------------
> If I have applied a label to the data.frame I get an
> error
> Error in data.frame(staff.allocation$site,
> staff.allocation$subject, staff.allocation$date,  : 
>  
>     arguments imply differing number of rows: 1865,
> 114
>         
> I orgininally was getting an error about
>  " staff.allocation$site is a labelled
> class and cannot be coerced into a data.frame" 
> 
> but I lost that one while trying to see what was
> happeing
>         
> If I do not apply the label to staff.allocation then
> I
> get a Class = "data.frame and I have no problem
> creating the second data.frame.
> 
> Can anyone suggest what I am missing or what is
> happening
> 
> Thanks

To follow up to my own post it appears that if I make
any changes in the imported labels I also get an error
message when I attempt to create that data.frame
The message is
Error in as.data.frame.default(x[[i]], optional =
TRUE) :  cannot coerce class "labelled" into a
data.frame



More information about the R-help mailing list