blob: dda985be6286dbb0275f2dcbe0a4d407f7a61ac8 [file] [log] [blame]
<!DOCTYPE html><html><head><title>R: Math functions for Column operations</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.css">
<script type="text/javascript">
const macros = { "\\R": "\\textsf{R}", "\\code": "\\texttt"};
function processMathHTML() {
var l = document.getElementsByClassName('reqn');
for (let e of l) { katex.render(e.textContent, e, { throwOnError: false, macros }); }
return;
}</script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.js"
onload="processMathHTML();"></script>
<link rel="stylesheet" type="text/css" href="R.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/languages/r.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head><body><div class="container">
<table style="width: 100%;"><tr><td>column_math_functions {SparkR}</td><td style="text-align: right;">R Documentation</td></tr></table>
<h2>Math functions for Column operations</h2>
<h3>Description</h3>
<p>Math functions defined for <code>Column</code>.
</p>
<h3>Usage</h3>
<pre><code class='language-R'>bin(x)
bround(x, ...)
cbrt(x)
ceil(x)
conv(x, fromBase, toBase)
hex(x)
hypot(y, x)
pmod(y, x)
rint(x)
shiftLeft(y, x)
shiftleft(y, x)
shiftRight(y, x)
shiftright(y, x)
shiftRightUnsigned(y, x)
shiftrightunsigned(y, x)
signum(x)
degrees(x)
toDegrees(x)
radians(x)
toRadians(x)
unhex(x)
## S4 method for signature 'Column'
abs(x)
## S4 method for signature 'Column'
acos(x)
## S4 method for signature 'Column'
acosh(x)
## S4 method for signature 'Column'
asin(x)
## S4 method for signature 'Column'
asinh(x)
## S4 method for signature 'Column'
atan(x)
## S4 method for signature 'Column'
atanh(x)
## S4 method for signature 'Column'
bin(x)
## S4 method for signature 'Column'
cbrt(x)
## S4 method for signature 'Column'
ceil(x)
## S4 method for signature 'Column'
ceiling(x)
## S4 method for signature 'Column'
cos(x)
## S4 method for signature 'Column'
cosh(x)
## S4 method for signature 'Column'
exp(x)
## S4 method for signature 'Column'
expm1(x)
## S4 method for signature 'Column'
factorial(x)
## S4 method for signature 'Column'
floor(x)
## S4 method for signature 'Column'
hex(x)
## S4 method for signature 'Column'
log(x)
## S4 method for signature 'Column'
log10(x)
## S4 method for signature 'Column'
log1p(x)
## S4 method for signature 'Column'
log2(x)
## S4 method for signature 'Column'
rint(x)
## S4 method for signature 'Column'
round(x)
## S4 method for signature 'Column'
bround(x, scale = 0)
## S4 method for signature 'Column'
signum(x)
## S4 method for signature 'Column'
sign(x)
## S4 method for signature 'Column'
sin(x)
## S4 method for signature 'Column'
sinh(x)
## S4 method for signature 'Column'
sqrt(x)
## S4 method for signature 'Column'
tan(x)
## S4 method for signature 'Column'
tanh(x)
## S4 method for signature 'Column'
toDegrees(x)
## S4 method for signature 'Column'
degrees(x)
## S4 method for signature 'Column'
toRadians(x)
## S4 method for signature 'Column'
radians(x)
## S4 method for signature 'Column'
unhex(x)
## S4 method for signature 'Column'
atan2(y, x)
## S4 method for signature 'Column'
hypot(y, x)
## S4 method for signature 'Column'
pmod(y, x)
## S4 method for signature 'Column,numeric'
shiftleft(y, x)
## S4 method for signature 'Column,numeric'
shiftLeft(y, x)
## S4 method for signature 'Column,numeric'
shiftright(y, x)
## S4 method for signature 'Column,numeric'
shiftRight(y, x)
## S4 method for signature 'Column,numeric'
shiftrightunsigned(y, x)
## S4 method for signature 'Column,numeric'
shiftRightUnsigned(y, x)
## S4 method for signature 'Column,numeric,numeric'
conv(x, fromBase, toBase)
</code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;"><td><code>x</code></td>
<td>
<p>Column to compute on. In <code>shiftLeft</code>, <code>shiftRight</code> and
<code>shiftRightUnsigned</code>, this is the number of bits to shift.</p>
</td></tr>
<tr style="vertical-align: top;"><td><code>...</code></td>
<td>
<p>additional argument(s).</p>
</td></tr>
<tr style="vertical-align: top;"><td><code>fromBase</code></td>
<td>
<p>base to convert from.</p>
</td></tr>
<tr style="vertical-align: top;"><td><code>toBase</code></td>
<td>
<p>base to convert to.</p>
</td></tr>
<tr style="vertical-align: top;"><td><code>y</code></td>
<td>
<p>Column to compute on.</p>
</td></tr>
<tr style="vertical-align: top;"><td><code>scale</code></td>
<td>
<p>round to <code>scale</code> digits to the right of the decimal point when
<code>scale</code> &gt; 0, the nearest even number when <code>scale</code> = 0, and <code>scale</code> digits
to the left of the decimal point when <code>scale</code> &lt; 0.</p>
</td></tr>
</table>
<h3>Details</h3>
<p><code>abs</code>: Computes the absolute value.
</p>
<p><code>acos</code>: Returns the inverse cosine of the given value,
as if computed by <code>java.lang.Math.acos()</code>
</p>
<p><code>acosh</code>: Computes inverse hyperbolic cosine of the input column.
</p>
<p><code>asin</code>: Returns the inverse sine of the given value,
as if computed by <code>java.lang.Math.asin()</code>
</p>
<p><code>asinh</code>: Computes inverse hyperbolic sine of the input column.
</p>
<p><code>atan</code>: Returns the inverse tangent of the given value,
as if computed by <code>java.lang.Math.atan()</code>
</p>
<p><code>atanh</code>: Computes inverse hyperbolic tangent of the input column.
</p>
<p><code>bin</code>: Returns the string representation of the binary value
of the given long column. For example, bin(&quot;12&quot;) returns &quot;1100&quot;.
</p>
<p><code>cbrt</code>: Computes the cube-root of the given value.
</p>
<p><code>ceil</code>: Computes the ceiling of the given value.
</p>
<p><code>ceiling</code>: Alias for <code>ceil</code>.
</p>
<p><code>cos</code>: Returns the cosine of the given value,
as if computed by <code>java.lang.Math.cos()</code>. Units in radians.
</p>
<p><code>cosh</code>: Returns the hyperbolic cosine of the given value,
as if computed by <code>java.lang.Math.cosh()</code>.
</p>
<p><code>exp</code>: Computes the exponential of the given value.
</p>
<p><code>expm1</code>: Computes the exponential of the given value minus one.
</p>
<p><code>factorial</code>: Computes the factorial of the given value.
</p>
<p><code>floor</code>: Computes the floor of the given value.
</p>
<p><code>hex</code>: Computes hex value of the given column.
</p>
<p><code>log</code>: Computes the natural logarithm of the given value.
</p>
<p><code>log10</code>: Computes the logarithm of the given value in base 10.
</p>
<p><code>log1p</code>: Computes the natural logarithm of the given value plus one.
</p>
<p><code>log2</code>: Computes the logarithm of the given column in base 2.
</p>
<p><code>rint</code>: Returns the double value that is closest in value to the argument and
is equal to a mathematical integer.
</p>
<p><code>round</code>: Returns the value of the column rounded to 0 decimal places
using HALF_UP rounding mode.
</p>
<p><code>bround</code>: Returns the value of the column <code>e</code> rounded to <code>scale</code> decimal places
using HALF_EVEN rounding mode if <code>scale</code> &gt;= 0 or at integer part when <code>scale</code> &lt; 0.
Also known as Gaussian rounding or bankers' rounding that rounds to the nearest even number.
bround(2.5, 0) = 2, bround(3.5, 0) = 4.
</p>
<p><code>signum</code>: Computes the signum of the given value.
</p>
<p><code>sign</code>: Alias for <code>signum</code>.
</p>
<p><code>sin</code>: Returns the sine of the given value,
as if computed by <code>java.lang.Math.sin()</code>. Units in radians.
</p>
<p><code>sinh</code>: Returns the hyperbolic sine of the given value,
as if computed by <code>java.lang.Math.sinh()</code>.
</p>
<p><code>sqrt</code>: Computes the square root of the specified float value.
</p>
<p><code>tan</code>: Returns the tangent of the given value,
as if computed by <code>java.lang.Math.tan()</code>.
Units in radians.
</p>
<p><code>tanh</code>: Returns the hyperbolic tangent of the given value,
as if computed by <code>java.lang.Math.tanh()</code>.
</p>
<p><code>toDegrees</code>: Converts an angle measured in radians to an approximately equivalent angle
measured in degrees.
</p>
<p><code>degrees</code>: Converts an angle measured in radians to an approximately equivalent angle
measured in degrees.
</p>
<p><code>toRadians</code>: Converts an angle measured in degrees to an approximately equivalent angle
measured in radians.
</p>
<p><code>radians</code>: Converts an angle measured in degrees to an approximately equivalent angle
measured in radians.
</p>
<p><code>unhex</code>: Inverse of hex. Interprets each pair of characters as a hexadecimal number
and converts to the byte representation of number.
</p>
<p><code>atan2</code>: Returns the angle theta from the conversion of rectangular coordinates
(x, y) to polar coordinates (r, theta),
as if computed by <code>java.lang.Math.atan2()</code>. Units in radians.
</p>
<p><code>hypot</code>: Computes &quot;sqrt(a^2 + b^2)&quot; without intermediate overflow or underflow.
</p>
<p><code>pmod</code>: Returns the positive value of dividend mod divisor.
Column <code>x</code> is divisor column, and column <code>y</code> is the dividend column.
</p>
<p><code>shiftleft</code>: Shifts the given value numBits left. If the given value is a long value,
this function will return a long value else it will return an integer value.
</p>
<p><code>shiftLeft</code>: Shifts the given value numBits left. If the given value is a long value,
this function will return a long value else it will return an integer value.
</p>
<p><code>shiftright</code>: (Signed) shifts the given value numBits right. If the given value is a long
value, it will return a long value else it will return an integer value.
</p>
<p><code>shiftRight</code>: (Signed) shifts the given value numBits right. If the given value is a long
value, it will return a long value else it will return an integer value.
</p>
<p><code>shiftrightunsigned</code>: (Unsigned) shifts the given value numBits right. If the given value is
a long value, it will return a long value else it will return an integer value.
</p>
<p><code>shiftRightUnsigned</code>: (Unsigned) shifts the given value numBits right. If the given value is
a long value, it will return a long value else it will return an integer value.
</p>
<p><code>conv</code>: Converts a number in a string column from one base to another.
</p>
<h3>Note</h3>
<p>abs since 1.5.0
</p>
<p>acos since 1.5.0
</p>
<p>acosh since 3.1.0
</p>
<p>asin since 1.5.0
</p>
<p>asinh since 3.1.0
</p>
<p>atan since 1.5.0
</p>
<p>atanh since 3.1.0
</p>
<p>bin since 1.5.0
</p>
<p>cbrt since 1.4.0
</p>
<p>ceil since 1.5.0
</p>
<p>ceiling since 1.5.0
</p>
<p>cos since 1.5.0
</p>
<p>cosh since 1.5.0
</p>
<p>exp since 1.5.0
</p>
<p>expm1 since 1.5.0
</p>
<p>factorial since 1.5.0
</p>
<p>floor since 1.5.0
</p>
<p>hex since 1.5.0
</p>
<p>log since 1.5.0
</p>
<p>log10 since 1.5.0
</p>
<p>log1p since 1.5.0
</p>
<p>log2 since 1.5.0
</p>
<p>rint since 1.5.0
</p>
<p>round since 1.5.0
</p>
<p>bround since 2.0.0
</p>
<p>signum since 1.5.0
</p>
<p>sign since 1.5.0
</p>
<p>sin since 1.5.0
</p>
<p>sinh since 1.5.0
</p>
<p>sqrt since 1.5.0
</p>
<p>tan since 1.5.0
</p>
<p>tanh since 1.5.0
</p>
<p>toDegrees since 1.4.0
</p>
<p>degrees since 3.0.0
</p>
<p>toRadians since 1.4.0
</p>
<p>radians since 3.0.0
</p>
<p>unhex since 1.5.0
</p>
<p>atan2 since 1.5.0
</p>
<p>hypot since 1.4.0
</p>
<p>pmod since 1.5.0
</p>
<p>shiftleft since 3.2.0
</p>
<p>shiftLeft since 1.5.0
</p>
<p>shiftright since 3.2.0
</p>
<p>shiftRight since 1.5.0
</p>
<p>shiftrightunsigned since 3.2.0
</p>
<p>shiftRightUnsigned since 1.5.0
</p>
<p>conv since 1.5.0
</p>
<h3>Examples</h3>
<pre><code class="r">## Not run:
##D # Dataframe used throughout this doc
##D df &lt;- createDataFrame(cbind(model = rownames(mtcars), mtcars))
##D tmp &lt;- mutate(df, v1 = log(df$mpg), v2 = cbrt(df$disp),
##D v3 = bround(df$wt, 1), v4 = bin(df$cyl),
##D v5 = hex(df$wt), v6 = degrees(df$gear),
##D v7 = atan2(df$cyl, df$am), v8 = hypot(df$cyl, df$am),
##D v9 = pmod(df$hp, df$cyl), v10 = shiftLeft(df$disp, 1),
##D v11 = conv(df$hp, 10, 16), v12 = sign(df$vs - 0.5),
##D v13 = sqrt(df$disp), v14 = ceil(df$wt))
##D head(tmp)
## End(Not run)
</code></pre>
<hr /><div style="text-align: center;">[Package <em>SparkR</em> version 3.2.2 <a href="00Index.html">Index</a>]</div>
</div>
</body></html>