[R] transform variables

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Mon Aug 26 14:28:35 CEST 2013


Catalin,

first, keep the communication on the list, so it gets documented also for 
others.

Second, my code does work for an example I made up myself, but if you 
don't "provide commented, minimal, self-contained, reproducible code" (as 
the posting guide asks you to; see last line of this e-mail), it is 
unlikely that someone could be of further help.

Regards  -- Gerrit

On Mon, 26 Aug 2013, catalin roibu wrote:

> Hello!
> Your code give me the same month values for each year from interval. I want
> 12 month for each year!.
> Eg
> year month value
> 1901 1      3.5
> 1901 2      2.5
>
>
> On 26 August 2013 14:35, Gerrit Eichner
> <Gerrit.Eichner at math.uni-giessen.de>wrote:
>
>> Hello, Catalin,
>>
>> assume your data frame is as simple as
>>
>>  A <- data.frame( year = <years>, month01 = <values01>, ....,
>>>
>> +                  month12 = <values12>)
>>
>> then, e.g.,
>>
>>  reshape( A, varying = c( "month01", ...., "month12"),
>>>
>> +          v.names = "Values", timevar = "Month", direction = "long")
>>
>> should do what you want. For details see ?reshape
>>
>> Hth  -- Gerrit
>>
>>
>>
>> On Mon, 26 Aug 2013, catalin roibu wrote:
>>
>>  Dear all!
>>>
>>> I have a data frame composed by 13 columns (year, and 12 months). I want
>>> to
>>> transform this data base in another like this
>>> year month values
>>> 1901 1
>>> 1901 2
>>> 1901 3
>>> .....
>>> 1901 12
>>> 1902  1
>>> 1902  2
>>> ....
>>> 1902  12
>>>
>>> Is there a possibility to succeed that in R?
>>>
>>> Thank you!
>>>
>>> best regards!
>>> CR
>>>
>>> --
>>> ---
>>> Catalin-Constantin ROIBU
>>> Lecturer PhD, Forestry engineer
>>> Forestry Faculty of Suceava
>>> Str. Universitatii no. 13, Suceava, 720229, Romania
>>> office phone     +4 0230 52 29 78, ext. 531
>>> mobile phone   +4 0745 53 18 01
>>>                       +4 0766 71 76 58
>>> FAX:                +4 0230 52 16 64
>>> silvic.usv.ro
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________**________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>
>
> -- 
> ---
> Catalin-Constantin ROIBU
> Lecturer PhD, Forestry engineer
> Forestry Faculty of Suceava
> Str. Universitatii no. 13, Suceava, 720229, Romania
> office phone     +4 0230 52 29 78, ext. 531
> mobile phone   +4 0745 53 18 01
>                       +4 0766 71 76 58
> FAX:                +4 0230 52 16 64
> silvic.usv.ro



More information about the R-help mailing list