Skip to content
Prev 246958 / 398503 Next

From vector to a step function

try this:
+     breaks <- seq(-3, by = 1, length = length(vec) + 1L)
+     function(x){
+         indx <- findInterval(x, breaks)
+         vec[indx]
+     }
+ }
[1] 3 4 5 1 1 2 3
[1] 5 6 2 4 4 7 3
[1] 1 2 4 7 7 3 1

        
On Mon, Jan 10, 2011 at 11:42 AM, Alaios <alaios at yahoo.com> wrote: