On Aug 17, 2011, at 5:49 PM, Frank Harrell wrote:
I'm puzzled. I provided a solution that did not require looping.
Frank
Hi Frank;
Do you realize that some portions of your Nabble postings are not
being communicated to the ordinary mail-clients? This code did not
appear in my copy from Nabble. I didn't cut anything. This appears in
Nabble when you look there:
> d <- data.frame(a=1:2,b=3:4)
> label(d, self=FALSE) <- c('A','B')
> contents(d)
Data frame:d 2 observations and 2 variables Maximum # NAs:0 Labels
Storage a A integer
b B integer
I observed and noted that was happening in a prior message. The
missing formatted Nabble studd also comes across without linefeeds
when pasted, so I added some of those back in.
--
David.
Monsieur Do wrote:
I did read the help page before posting, but didn't find the direct
way...
My function here works fine. But just for learning purposes, I'd
like to
be able to avoid the loop...
with.labels <- function(x, labels=NULL, csvfile=NULL) {
if(!is.null(csvfile)) labels <- read.csv(csvfile, sep="\t", header=F,
stringsAsFactors=F)[,1]
for(i in 1:length(x)) label(x[,i]) <- labels[i]
if(length(labels) != length(x)) cat("Warning: data and labels are
not of
same length\n")
return(x)
}
Thanks
Message: 11
Date: Tue, 16 Aug 2011 04:22:07 -0700 (PDT)
From:
Frank Harrell <f.harr...@vanderbilt.edu>
To:
r-help@r-project.org
Subject:
Re: [R] Labelling all variables at once (using Hmisc label)
Message-ID:
<1313493727519-3746928.p...@n4.nabble.com>
Content-Type:
text/plain; charset=UTF-8
Do
require(Hmisc); ?label to see the help file for label. It will
show you
how to
do this:
Monsieur
Do wrote:
>
I have a dataset and a list of labels. I simply want
> to
apply the labels to the variables, all at once. The only way I was
able
> to do
it was using a loop:
>
> for (i in 1:length(data)) label(data[,i]) <-data.labels[i]
>
> I'd like to find the non-loop way to do it, using
>
apply or the like... Any help appreciated.
>
-----
Frank
Harrell
Department
of Biostatistics, Vanderbilt University
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
-----
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context:
http://r.789695.n4.nabble.com/Labelling-all-variables-at-once-using-Hmisc-label-tp3745660p3751273.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.