[R] dataframe manipulation

Marc Schwartz marc_schwartz at comcast.net
Wed Nov 22 20:30:45 CET 2006


On Wed, 2006-11-22 at 20:27 +0100, antonio rodriguez wrote:
> Hi,
> 
> Having a dataframe 'l1' (dput output is below):
> 
>  >dim(l1)
> 1274   2
> 
>  >l1[1:12,]
> 
>             Var1 Freq
> 1  1988-01-13    1
> 2  1988-01-16    1
> 3  1988-01-20    3
> 4  1988-01-25    2
> 5  1988-01-30    1
> 6  1988-02-01    5
> 7  1988-02-08    4
> 8  1988-02-14    1
> 9  1988-02-16    1
> 10 1988-02-18    4
> 11 1988-02-24    2
> 12 1988-03-04    1
> 
> 
> I want to extract the times "1988-01", "1988-02",...,"2005-12"  are 
> present, in order to know, for example, that 1988-01 = 5 days   1988-02 
> = 6 days and so on. The Freq column doesn't matter in this case, just 
> the Var1 column
> 
> I've been trying with:
> 
> regexpr("2005-03-",l1$Var1) 
> 
> But the result is not satisfactory since I need to find and count where 
> these values are.
> 
> Thanks
> 
> Antonio

Using just the example data:

> table(substr(DF$Var1, 1, 7))

1988-01 1988-02 1988-03 
      5       6       1 

See ?substr for more information.

HTH,

Marc Schwartz



More information about the R-help mailing list