[R] returning a modified fix()-ed dataframe
Adrian DUSA
dusa.adrian at gmail.com
Fri Oct 7 19:12:17 CEST 2005
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.
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.
2. is it possible to change the width of a column?
Thank you,
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