[R] returning a modified fix()-ed dataframe

From: Adrian DUSA <dusa.adrian_at_gmail.com>
Date: Sat 08 Oct 2005 - 02:44:49 EST

Dear all,

In order to ease the transition from SPSS to R for some of my colleagues, I am trying to create a function which would show the variables and their labels (if those exist), using function "label" in package Hmisc.

A toy example would be this:

my.data <- data.frame(age=c(24,35,28), gender=c("Male", "Female", "Male")) require(Hmisc)
label(my.data$age) <- "Respondent's age" label(my.data$gender) <- "Responent's gender"

variables <- function(x) {

        dataf <- data.frame(variable=NA, label=NA)
        varlab <- NA
        for (i in 1:length(names(x))) {
                dataf[i,1] <- names(x)[i]
                dataf[i,2] <- label(x[,i])
                varlab[i] <- label(x[,i])

}
fix(dataf) # I assume this would return a modified dataf for (i in which(varlab != dataf[,2])) { label(x[,i]) <- dataf[i,2]
}

}

Now, say during fix() one modified "Responent's gender" into "Respondent's gender" (the previous missed a "d"). The trouble I'm having is to return the modified object, with the modified labels. It should be easy, I feel it, but I just can't get it.

Thank you in advance,
Adrian

-- 
Adrian DUSA
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Oct 08 03:54:46 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:39 EST