R code. write a floor function -


I want to write a floor function in R, which is why a floating number gives your nearest integer I tried down function Of It seems that it allocates the value if I X works and runs the code inside the function would, but when I try to put everything in function would later call the function name it Fails

Do anyone know how to fix that? Thanks!

  & gt; My_floor & lt; - Function (x) {x & lt; - x-0.5 as.integer (x) returns (x)} & gt; Y & lt; - 3.1052255 & gt; My_floor (y) [1] 2.605225    

Not quite sure what you But if you just want to convert the input to the nearest integer for the nearest of zero (i.e. floors as you run your question), then there will be a way to do this: / P>

This leaves the integer part of your input using RK trunc : which you call directly That means trunc (y) will still give you the desired results. If you want to use your function above "as is" then:

my_floor & lt; - Function (x) {x & lt; -x-0.5x & lt; Prevent the results of this second step by reassigning as.integer (x) #x Return (x)}

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -