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

John Kane jrkrideau at yahoo.ca
Tue Aug 1 19:43:01 CEST 2006


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



More information about the R-help mailing list