[R] Correcting the display of colnames and rownames

From: Steve Murray <smurray444_at_hotmail.com>
Date: Sat, 14 Jun 2008 00:27:40 +0000

Dear all,

I have a data frame of dimension 720 columns by 360 rows, to which I am trying to add numerical row and column labels to, using the 'sequence' command. The original data, which I read in using 'read.table', had no such labels at all.

I've got as far as successfully using the sequence command and getting the labels to display. However, I'm finding that for the minus numbers in particular, the values aren't displaying correctly. For the value '-179.75' for example, it displays as 'X.179.75'. Even for positive numbers, the 'X' prefix appears at the start of the label (but without the '.').

I have tried numerous attempts at addressing this. I'm currently as far as adopting the following approach; I'll show what I've done for just the column headings - I've adopted the same approach for row headings, with the same results/problem so far.

columnnames <- seq(from = -179.75, to = 179.75, length = 720) as.numeric <- colnames(Jan)
colnames(Jan) <- make.names(columnnames)

N.B. 'Jan' (as in January) refers to the data frame in question.

So my thinking here is to assign the values to be used as column labels to 'columnnames', and use 'make.names' to assign these values to the column names of the data frame. I've also tried changing 'colnames(Jan)' to be a numeric class, as I was previously having problems assigning the values to the labels - I think because by default 'colnames' is of class 'character vector'?

If anyone is able to suggest a way how I can solve the problem of the values not being displayed as I'd hoped (namely, removing the 'X' and displaying '-' for minus numbers), then I'd be very grateful.

Many thanks,

Steve


        [[alternative HTML version deleted]]



R-help_at_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. Received on Sat 14 Jun 2008 - 00:42:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 14 Jun 2008 - 23:31:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive