On 15-05-2013, at 08:15, catalin roibu <catalinro...@gmail.com> wrote:

> Hello all!
> I have a problem with my data.
> My initial data is a list years and months (see below). I want to transpose
> my data (12 rows (months) and year values as column). I try t(spi3), but
> the year values do not appear as column names, but as values.

As expected since the column year is a column of numbers and is printed with 
the appropriate number of decimals for each column.
You can get what you want in two ways.

I've called your initital dataframe DF.

First transpose DF, then set the column names to the contents of the year row 
and finally delete the first row (the year row).

DF.t <- t(DF)
colnames(DF.t) <- DF.t["year",]
DF.t <- DF.t[-1,]
DF.t

The second method is to put DF in the form you apparently want and then 
transpose.
So set the rownames of DF to the column "year", delete the year column and then 
transpose.

rownames(DF) <- DF[,"year"]
DF <- DF[,-1]
t(DF)

Berend

______________________________________________
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.

Reply via email to