Adrian DUSA wrote: > On Friday 07 October 2005 20:55, Sundar Dorai-Raj wrote: > >>Adrian DUSA wrote: >> >>>[...snip...] >> >>Hi, Adrian, >> >>You need to assign "fix(dataf)" to something: >> >>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]) >> } >> dataf <- fix(dataf) >> # I assume this would return a modified dataf >> for (i in which(varlab != dataf[,2])) { >> label(x[,i]) <- dataf[i,2] >> } >> # don't forget to return dataf >> dataf >>} >> >>variables(my.data) >> >>HTH, >> >>--sundar > > > Hi Sundar, > > Hm... the new function correctly returns (and prints) dataf but I need to > return my.data... > I also thought about returning my.data, but if this would be a large > dataframe, printing it wouldn't be so nice. > Basically, I would need to somehow silently return the input (modified) > dataframe. >
Then assign the return of "variables" back to my.data. my.data <- variables(my.data) My guess is you want to have your function fix my.data without having to reassign it. The answer to that question is most likely a road you do not want to travel. Otherwise, try searching the archives for "assign reference" for some clues. > Also, I now have another related two questions: > 1. is it possible to "edit" the contents of a cell when using fix() ? In > order > to change a letter one would have to change the whole string. Double-click on the field. > 2. is it possible to change the width of a column? > Right-click on the column then select auto-size column. Or left-click on a column line and drag to desired width. View the Help from right-clicking for other options. > Thank you, > Adrian > Your welcome, --sundar ______________________________________________ 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