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

  • Home
  • SEARCH
  • 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 9301137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:56:46+00:00 2026-06-18T22:56:46+00:00

I have a factor variable represented by the histogram bins with values: ‘660-664’ ,

  • 0

I have a factor variable represented by the histogram bins with values: ‘660-664’ , … , ‘740-744′ , 745-749’ ..

How can I map the factor variable to its mean value, e.g mapping ‘660-664’ to 662?

Basically, what I’m looking for is the inverse of the “cut” function.

  • 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-18T22:56:47+00:00Added an answer on June 18, 2026 at 10:56 pm

    You can make use of the plot = FALSE argument from hist to extract the breaks, then use that to get your midpoints:

    set.seed(1)
    x <- sample(300, 30)
    x
    #  [1]  80 112 171 270  60 266 278 194 184  18 296  52 198 111 221 142
    # [17] 204 281 108 219 262 290 182  35  74 107   4 105 237  93
    temp <- hist(x, plot = FALSE)$breaks
    temp
    # [1]   0  50 100 150 200 250 300
    rowMeans(cbind(head(temp, -1),
                   tail(temp, -1)))
    # [1]  25  75 125 175 225 275
    

    Update: Calculating the mean from a character string of ranges

    Judging by your comments, you might be looking for something more like this:

    myVec <- c("735-739", "715-719", "690-694", "695-699", "695-699",
               "670-674", "720-724", "705-709", "685-689")
    myVec
    # [1] "735-739" "715-719" "690-694" "695-699" "695-699" "670-674"
    # [7] "720-724" "705-709" "685-689"
    sapply(strsplit(myVec, "-"), function(x) mean(as.numeric(x)))
    # [1] 737 717 692 697 697 672 722 707 687
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a factor variable which is comprised of times. When I attempt to
I have a variable that is a factor : $ year : Factor w/
I have simple histogram, but can't adjust the binwidth: qplot(factor(size_class),data=mydf,geom=histogram,binwidth = 0.01) size_class is
I have the following data frame (simplified) with the country variable as a factor
I have a list of double values, I want to Round a variable's value
I have a column that's a factor variable. I need to change the value
I have a data frame and I'm trying to take a factor variable and
I have data collected from a survey. One factor variable is like this: Column1
I have data frame with some numerical variables and some categorical factor variables. The
I have a factor a : > a [1] foo [2] bar [3] foo

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.