[R] returning a modified fix()-ed dataframe
Adrian DUSA
dusa.adrian at gmail.com
Fri Oct 7 18:44:49 CEST 2005
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
More information about the R-help
mailing list