Here is an approach that should work: > x <- data.frame(a=1:10, b=1:10, c=1:10) > # use sprintf to make consistent numbers > myNames <- sprintf("%.2f", seq(from=-179, to=179, length=3)) > colnames(x) <- myNames > x -179.00 0.00 179.00 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 >
On Fri, Jun 13, 2008 at 8:27 PM, Steve Murray <[EMAIL PROTECTED]> wrote: > > 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@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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? ______________________________________________ R-help@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.