[R] Help with dimnames()

Roger Bivand Roger.Bivand at nhh.no
Tue Jun 20 19:29:34 CEST 2006


On Tue, 20 Jun 2006, Smith, Phil (CDC/NIP/DMD) wrote:

> Hi R people:
> 
> I'm trying to set the dimnames of a data frame called "ests" and am
> having trouble!
> 
> First, I check to see if "ests" is a data.frame... 
> 
> > is.data.frame( ests )
> [1] TRUE
> 
> ... and it is a data frame!
> 
> Next, I try to assign dimnames to that data frame....
> 
> > dimnames( ests )[[ 1 ]] <- as.character( ests$stfips )
> Error in "row.names<-.data.frame"(`*tmp*`, value = c("1001", "1003",
> "1005",  : 
>         missing 'row.names' are not allowed
> 

ests <- data.frame(x=runif(50), y=runif(50))
stfips <- c(letters[1:25], LETTERS[1:25])
is.na(stfips) <- 50
dimnames( ests )[[ 1 ]] <- as.character(stfips)

reproduces the error message, and:

which(is.na(stfips))

says which stfips is missing. If more than one is missing, the error 
message is different. 


> ... and I have trouble!!
> 
> Finally, I check to see if ests$stfips has the same length as the number
> of rows in "ests"...
> 
> > nrow( ests ) == length( as.character( ests$stfips ) )
> [1] TRUE
> 
> ... and it does!!
> 
> Does anybody have a suggestion to solve this problem?
> 
> Thanks!
> Phil Smith
> pzs6 at cdc.gov
> National Immunization Program
> Centers for Disease Control and Prevention
> Atlanta, GA
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-help mailing list