[R] creating series of vectors
Nino Pierantonio
nino.p.80 at gmail.com
Tue Feb 21 18:10:11 CET 2012
Thanks Ilai this helped.
Cheers,
Nino
Il 16/02/2012 23:15, ilai ha scritto:
> # All days in years 2006 to 2009 by month in 48 (12x4) files.
>
> days<- seq(as.Date("2006/1/1"), as.Date("2009/12/31"),by="day") # one
> long vector
> out<- paste(rep(format(days,'%d%m%y'),each=2),c('aaa','bbb'),sep='_')
> # reformat to style
> month<- factor(rep(format(days,'%B%y'),each=2)) # group by month.year
> for(i in levels(month))
> cat(out[month==i],'\n',file=paste(i,'txt',sep='.')) # write external
> files
>
> Cheers
>
> On Thu, Feb 16, 2012 at 9:32 AM, Nino Pierantonio<nino.p.80 at gmail.com> wrote:
>> Dear All,
>>
>> I am pretty new to R and thus my question may sound silly.
>>
>> Is there a way to automatically generate a series of separate vectors (so
>> not arranged in a matrix), without typing and changing every time the
>> values, and store them as separate *xlsx file, where the "*" is replaced by
>> the name of the vector itself?
>>
>> What i would like to create is a total of 12 vectors, corresponding to the
>> 12 months (January to December), say for the year 2006; thus the name of a
>> resulting single vector should be something like "January2006", and the
>> final file that will be stored in my WD should have the same name
>> ("January2009.xlsx").
>>
>> The number of the elements of each vector must correspond to the length in
>> days of the single months (considering a non-leap-year, 356 days) multiplied
>> by 2 (e.g. "January2006" will have 31*2=62 elements, "February2006" will
>> have 28*2=56 elements, and so on).
>>
>> Finally, the elements of the vectors should be named as:
>> "010106_aaa","010106_bbb","020106_aaa","020106_bbb", ... ,
>> "310106_aaa","310106_bbb".
>>
>> To sum up, at the end of the process i would like to obtain 12 vectors as it
>> follows:
>>
>> Jauary2006("010106_aaa","010106_bbb","020106_aaa","020106_bbb", ... ,
>> "310106_aaa","310106_bbb")
>> .
>> .
>> .
>> .
>> .
>> December2006("010106_aaa","010106_bbb","020106_aaa","020106_bbb", ... ,
>> "310106_aaa","310106_bbb")
>>
>> Any help would be particularly welcome and appreciated.
>> Cheers,
>>
>> NP
>>
>> * Italiano - rilevata
>> * Inglese
>> * Italiano
>> * Francese
>> * Spagnolo
>> * Tedesco
>>
>> * Inglese
>> * Italiano
>> * Francese
>> * Spagnolo
>> * Tedesco
>>
>> <javascript:void(0);>
>>
>> ______________________________________________
>> 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.
>
--
Nino Pierantonio
Mobile: +39 349.532.9370
Skype: pierantonio_nino
More information about the R-help
mailing list