[R] Cut a within elements by length, not value, of vectors
Erik Iverson
eriki at ccbr.umn.edu
Thu Jul 15 19:40:44 CEST 2010
btc1 wrote:
> Hello, I have a vector, "dates", as a series of 3 digit elements, i.e. > date
> [1] 528 528 528 528 528 528 528 528 528 528 528 528 708 708 708 708 708
> 708
> [19] 708 708 708 708 529 529 529 529 529 529 529 529 529 529 529 529 529
> 529
> [37] 529 624
>
> I need to convert them into julian, but have to insert a "/" or "-" after
> the first number within each element of the vector (5/28 5/28 etc). Found
> plenty functions to replace by a pattern but not to cut by a certain number
> of digits with an element. Alternately, if I could run all the elements into
> one long vector and then cut every one then two digits, that would work as
> well.
And what about the year? You might have better luck using the Date
class in R.
#not tested
as.Date("05282010", format = "%m%d%Y")
More information about the R-help
mailing list