[R] " Error in "names<-.default"

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Oct 4 18:26:43 CEST 2006


On Wed, 2006-10-04 at 16:07 +0100, nalluri pratap wrote:
> Hi All,
>    
>   Can some one explain me the following error-
>    
>   " Error in "names<-.default"
>   'names' attribute [1199] must be the same length as the vector [17]".
>    
>   Thanks,
>   Pratap

You haven't shown us what you did, but it looks like you tried to
replace the names of an object with a vector (of length 1199) when a
vector of length 17 was required. See this example:

dat <- as.data.frame(matrix(rnorm(100), ncol = 10))
names(dat) <- LETTERS[1:10]
names(dat)
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
names(dat) <- LETTERS
Error in `names<-.default`(`*tmp*`, value = c("A", "B", "C", "D", "E",  :
        'names' attribute [26] must be the same length as the vector [10]

Where I have tried to replace names(dat) (which should be of length 10)
with a vector of length 26 (all the letters A-Z).

The error message above is not the same as the one you show though, so
this might not be the problem. As the posting guide asks, please give a
reproducible example or provide enough information for us to help you.

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC & ENSIS, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list