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 8714715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:39:53+00:00 2026-06-13T05:39:53+00:00

I wanted to divide one column by another to get the per person time

  • 0

I wanted to divide one column by another to get the per person time how can I do this?I couldn’t find anything on how you can divide.

Here is some data that I want to use

     min    count2.freq
263807.0    1582
196190.5    1016
586689.0    3479

In the end I want to add a third column like this that has the number from min / count2.freq

e.g 263808.0/1582 = 166.75

  • 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-06-13T05:39:54+00:00Added an answer on June 13, 2026 at 5:39 am

    There are a plethora of ways in which this can be done. The problem is how to make R aware of the locations of the variables you wish to divide.

    Assuming

    d <- read.table(text = "263807.0    1582
    196190.5    1016
    586689.0    3479
    ")
    names(d) <- c("min", "count2.freq")
    > d
           min count2.freq
    1 263807.0        1582
    2 196190.5        1016
    3 586689.0        3479
    

    My preferred way

    To add the desired division as a third variable I would use transform()

    > d <- transform(d, new = min / count2.freq)
    > d
           min count2.freq      new
    1 263807.0        1582 166.7554
    2 196190.5        1016 193.1009
    3 586689.0        3479 168.6373
    

    The basic R way

    If doing this in a function (i.e. you are programming) then best to avoid the sugar shown above and index. In that case any of these would do what you want

    ## 1. via `[` and character indexes
    d[, "new"] <- d[, "min"] / d[, "count2.freq"]
    
    ## 2. via `[` with numeric indices
    d[, 3] <- d[, 1] / d[, 2]
    
    ## 3. via `$`
    d$new <- d$min / d$count2.freq
    

    All of these can be used at the prompt too, but which is easier to read:

    d <- transform(d, new = min / count2.freq)
    

    or

    d$new <- d$min / d$count2.freq ## or any of the above examples
    

    Hopefully you think like I do and the first version is better 😉

    The reason we don’t use the syntactic sugar of tranform() et al when programming is because of how they do their evaluation (look for the named variables). At the top level (at the prompt, working interactively) transform() et al work just fine. But buried in function calls or within a call to one of the apply() family of functions they can and often do break.

    Likewise, be careful using numeric indices (## 2. above); if you change the ordering of your data, you will select the wrong variables.

    The preferred way if you don’t need replacement

    If you are just wanting to do the division (rather than insert the result back into the data frame, then use with(), which allows us to isolate the simple expression you wish to evaluate

    > with(d, min / count2.freq)
    [1] 166.7554 193.1009 168.6373
    

    This is again much cleaner code than the equivalent

    > d$min / d$count2.freq
    [1] 166.7554 193.1009 168.6373
    

    as it explicitly states that “using d, execute the code min / count2.freq. Your preference may be different to mine, so I have shown all options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to use 6 different textures on a cube, one per side, but
This is a interview Question which was asked and wanted to find an efficient
Wanted to know if there was a way one could query shelveset details from
Can you pass in an operation like divide by 2 or subtract 1 using
I Have one rectangle. I wanted to do some animated stuff with colour on
I wanted to logically divide a loop every 4 iterations. Say, for example, I'm
If I wanted to find the percentage of people that are from the zip
Basic question here, just got curious about coding a simple formula out, and wanted
I just wanted to do how this works. So I am in the vert
I wanted to get some expert suggestions on designing urls for our web app.

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.