MotaF MotaF - 1 year ago 119
R Question

R and MATLAB floor function,do they do the same job?

I am converting MATLAB code into R

xmin=floor( min( min(min(per1),min(per2)) , min(min(per3),min(per4)) ) );

Mathworks says

Round toward negative infinity

Does the R function floor performs the same job?I do not have MATLAB installed,that I can compare the two.

Answer Source

?floor says

‘floor’ takes a single numeric argument ‘x’ and returns a numeric vector containing the largest integers not greater than the corresponding elements of ‘x’.

The MATLAB help online describes floor as "round toward negative infinity", and the actual help text is

Y = floor(X) rounds each element of X to the nearest integer less than or equal to that element.

Since R's min() function takes multiple arguments, I think

xmin <- floor( min(per1,per2,per3,per4))

should be fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download