s-news
[Top] [All Lists]

Re: names function in base package

To: Robert A LaBudde <ral@lcfltd.com>
Subject: Re: names function in base package
From: Frank E Harrell Jr <f.harrell@vanderbilt.edu>
Date: Sat, 21 Jul 2007 14:18:30 -0500
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <0JLJ009XCMCIRVF3@vms040.mailsrvcs.net>
References: <462C66080003E0BE@hawk.dcu.ie> <313490.61655.qm@web62012.mail.re1.yahoo.com> <0JLJ009XCMCIRVF3@vms040.mailsrvcs.net>
User-agent: Thunderbird 1.5.0.10 (X11/20070403)
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

<Prev in Thread] Current Thread [Next in Thread>