On Sun, Mar 15, 2009 at 11:46 PM, diegol diego...@gmail.com wrote:
...Steve, ...
Actually Stavros (ΣΤΑΥΡΟΣ), not Stephen/Steve (ΣΤΕΦΑΝΟΣ). Both Greek,
but different names.
I still don't understand the analogy. I agree that in this case the R
approach is vectorized. However, your function
Using R 2.7.0 under WinXP.
I need to write a function that takes a non-negative vector and returns the
parallell maximum between a percentage of this argument and a fixed value.
Both the percentages and the fixed values depend on which interval x falls
in. Intervals are as follows:
From |
Hi,
I think you could get a cleaner solution using ?cut to split your data
in given ranges (the break argument), and then using this factor to
give the appropriate percentage.
Hope this helps,
baptiste
On 15 Mar 2009, at 20:12, diegol wrote:
Using R 2.7.0 under WinXP.
I need to
On Sun, Mar 15, 2009 at 4:12 PM, diegol diego...@gmail.com wrote:
...This could be done in Excel much tidier in my opinion (especially the
range_aux part), element by element (cell by cell)...
If you'd do it element-by-element in Excel, why not do it
element-by-element in R?
Create a table
Hello Stavros,
If you'd do it element-by-element in Excel, why not do it
element-by-element in R?
Well, actually I was hoping for a vectorized solution so as to avoid
looping. I need to use this formula on rather lengthy vectors and I wanted
to put R's efficiency to some good use. In any
Hello Baptiste,
I am not very sure how I'd go about that. Taking the range, perc and min
vectors from Stavros' response:
range= c(20,100,250,700,1000,Inf)*1000
perc = c(65,40,30,25,20,0)/100
min = c(0,14,40,75,175,250)*1000
For range to work as the breaks argument to cut, I think
Hi,
I don't use ?cut and ?split very much either, so this may not be good
advice. From what I understood of your problem, I would try something
along those lines,
range= c(20,100,250,700,1000,Inf)*1000
perc = c(65,40,30,25,20,0)/100
min = c(0,14,40,75,175,250)*1000
range = c(0, range)
Hello Baptiste,
Thanks so much for your help. This function which is basically your input
wrapped with curly brackets seems to work alright:
mr_2 - function(x){
range= c(20,100,250,700,1000,Inf)*1000
perc = c(65,40,30,25,20,0)/100
min = c(0,14,40,75,175,250)*1000
Using cut/split seems like gross overkill here. Among other things,
you don't need to generate labels for all the different ranges.
which(x=range)[1]
seems straightforward enough to me, but you could also use the
built-in function findInterval.
-s
That's what I meant by element-by -element. A vector in R corresponds
to a row or a column in Excel, and a vector operation in R corresponds
to a row or column of formulae, e.g.
Excel
A B C
1) 5 10 a1+b1 (= 15)
2) 3 2 a2+b2 (= 5)
etc.
R
A -
10 matches
Mail list logo