[R] RFE: vectorized behavior for as.POSIXct tz argument

David Winsemius dwinsemius at comcast.net
Fri Dec 2 22:47:49 CET 2011


On Dec 2, 2011, at 4:06 PM, Jack Tanner wrote:

> David Winsemius <dwinsemius <at> comcast.net> writes:
>
>> sapply(tz, function(ttt) as.POSIXct(x=x, tz=ttt,
>> origin="1960-01-01"),simplify=FALSE)
>
> Sure, there's no end of workarounds. It would just be consistent to  
> treat both
> the x and the tz arguments as vectors.

I've wondered abut that too. The function where I would like to see a  
dual vectorized application is 'rep'. In cases where the x argument is  
the same length as the 'times' or 'each' arguments I would like to see  
it produce  a vector that is sum(each) or tume(times) long.

The problem is most likely in the ambiguity of how to apply the  
arguments:

 > unlist(sapply(1:5, function(tt)  rep(1:5, each=tt)))
  [1] 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 1 1  
1 1 2 2 2 2 3
[40] 3 3 3 4 4 4 4 5 5 5 5 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5  
5 5 5


 > mapply("rep", x=1:5, each=1:5)
[[1]]
[1] 1

[[2]]
[1] 2 2

[[3]]
[1] 3 3 3

[[4]]
[1] 4 4 4 4

[[5]]
[1] 5 5 5 5 5

>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list