[R] Is there an equivalent * operator?

Duncan Murdoch murdoch at stats.uwo.ca
Thu Jul 24 12:45:04 CEST 2008


Williams, Robin wrote:
> Hi all, 
> Is there an equivalent to the general * operator in R, where * can
> represent any character? 
>   I have a dataset, one column being date, date ranging between
> April-September, 97-06. I would like to be able to acquire the data for
> a specific month, say September, so that I can take average temperatures
> for the month, etc. I thought I would be able to do something like 
> data.s1 <- subset(data,date=="**-Sep-**") 
> data.s1 
> but when I do 
> data.s1 
> I get "0 rows or 0-length row.names". 
>   Any idea of a simple way I can perform this task? 
> All dates are in the form xx-xxx-xx, EG 30-Sep-06. 
> Thanks for any assistance.  
grep() and related functions described on the same man page can match 
general regular expressions.  The pattern you want would be 
"^..-Sep-..$".  Read the man page; they have several options for output 
format.  They work on character vectors; if your data has already been 
converted to a date format, there are likely other options, e.g. 
converting the date with format %b (see ?strftime) so only the month is 
included.

Duncan Murdoch



More information about the R-help mailing list