r - 是否有向量化并行 max() 和 min()?

标签 r parallel-processing vectorization max minimum

我有一个包含“a”和“b”列的data.frame。我想添加名为“high”和“low”的列,它们包含 a 列和 b 列中的最高值和最低值。

有没有办法在不循环数据帧中的行的情况下执行此操作?

编辑:这是针对 OHLC 数据,因此高列和低列应包含同一行上 a 和 b 之间的最高和最低元素,而不是整个列中的最高和最低元素。抱歉,如果措辞不当。

最佳答案

听起来您正在寻找 pmaxpmin(“并行”最大/分钟):

Extremes                 package:base                  R Documentation

Maxima and Minima

Description:

     Returns the (parallel) maxima and minima of the input values.

Usage:

     max(..., na.rm = FALSE)
     min(..., na.rm = FALSE)

     pmax(..., na.rm = FALSE)
     pmin(..., na.rm = FALSE)

     pmax.int(..., na.rm = FALSE)
     pmin.int(..., na.rm = FALSE)

Arguments:

     ...: numeric or character arguments (see Note).

   na.rm: a logical indicating whether missing values should be
          removed.

Details:

     ‘pmax’ and ‘pmin’ take one or more vectors (or matrices) as
     arguments and return a single vector giving the ‘parallel’ maxima
     (or minima) of the vectors.  The first element of the result is
     the maximum (minimum) of the first elements of all the arguments,
     the second element of the result is the maximum (minimum) of the
     second elements of all the arguments and so on.  Shorter inputs
     are recycled if necessary.  ‘attributes’ (such as ‘names’ or
     ‘dim’) are transferred from the first argument (if applicable).

关于r - 是否有向量化并行 max() 和 min()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5591593/

相关文章:

r - Shiny R 应用程序让用户通过套索选择修改数据框

r - 使用Snow SOCK以外的集群进行并行计算

MATLAB:字符串元胞数组的比较

c - 矩阵乘法的自动向量化

r - 有效提取数据框中每列和行的最小值和索引,然后按值排名

r - 在 R CMD SHLIB 中构建标志

r - 调整 ggplot2 中轴文本的 "margin"空间

java - 'parallelizing' 我的 for 循环是正确的选择吗? (没有 JNI/OPENMP)

r - 无法为并行集群打开套接字

r - 根据单独的列计算列中的间隔总和