Robert A LaBudde wrote:
At 02:36 PM 7/21/2007, Carol wrote:
Hi,
How to name the attributes of an object by name function? Why do I get
err msg?
thanks
x = c(1,2,3,4)
> names(x) = LETTERS[1:4]
Error in "names<-"(`*tmp*`, value = c("A", "B", "C", "D")) :
no applicable method for "names<-"
names(x) has to be a list of 4 strings.
LETTERS[1:4] is a single string 4 characters long.
Try
names(x)<- c('a','b','c','d')
No, LETTERS[1:4] is a vector of single-character strings. The length of
the vector is 4. And names(x) needs to be a vector, not a list.
In R:
LETTERS[1:4]
[1] "A" "B" "C" "D"
> x <- 1:4
> names(x) <- LETTERS[1:4]
> x
A B C D
1 2 3 4
Frank
================================================================
Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: ral@lcfltd.com
Least Cost Formulations, Ltd. URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239 Fax: 757-467-2947
"Vere scire est per causas scire"
================================================================
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
|