Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4246756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:01:01+00:00 2026-05-21T04:01:01+00:00

I have a data.frame with columns a and b. I want to add columns

  • 0

I have a data.frame with columns “a” and “b”. I want to add columns called “high” and “low” that contain the highest and the lowest among columns a and b.

Is there a way of doing this without looping over the lines in the dataframe?

edit: this is for OHLC data, and so the high and low column should contain the highest and lowest element between a and b on the same line, and not among the whole columns. sorry if this is badly worded.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:01:02+00:00Added an answer on May 21, 2026 at 4:01 am

    Sounds like you’re looking for pmax and pmin (“parallel” max/min):

    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).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data.frame that contains many columns. I want to keep the rows
I have a data frame filled with factor columns, and I want to add
I have a data frame where some of the columns contain NA values. How
I have a data frame with 50000 rows and 200 columns. There are duplicate
I have a data frame that is some 35,000 rows, by 7 columns. it
Let's assume that we have a data frame x which contains the columns job
Suppose that you have a data frame with many rows and many columns. The
I'm have a data frame without columns: df<-data.frame(v1=c(1:10), v2=seq(1, 100, length=10)) I want to
Suppose I have an R data frame with columns that specify location (lat/long), height,
I have a data frame that looks like this, with two key columns and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.