Question

I am working on a tutorial r question set where I need to create a "new"...

I am working on a tutorial r question set where I need to create a "new" variable that characterizes "old" in the following manner. Define a tract to have a low rate, less than the median for the data set, medium rate between medium and 75 percentile, and high if the rate is higher than 75 percentile.

What would the r code look like? Not sure how to pull "old" variable out of the data set and define a high, medium and low tract.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Suppose D is the dataset.

The code is as follows:

x <- D$old ### where old is the "old" variable you have referred to.

(Now, assuming that the median is the median of the "old" variable, we can proceed as below)

m <- median(x)

p75 <- quantile(x,0.75)

n <- length(x)

new <- rep(0,length=n)

for(i in 1:n)

{

if(x[i] <= m) new[i] <- "low"

if(x[i]>m & x[i] <= p75) <- "medium"

if(x[i] > p75) <- "high"

}

Note: The resulting variable "new" will be of the type "character", which is a categorical type of variable. To convert it into numeric form, the following code can be used:

new1 <- as.factor(new)

Hope this helps!

Add a comment
Know the answer?
Add Answer to:
I am working on a tutorial r question set where I need to create a "new"...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi! I know I don't include the data set I am working with in SAS 9.4,...

    Hi! I know I don't include the data set I am working with in SAS 9.4, but I was wondering if someone could show me an example as to how this would look. I know from the directions that I am supposed to have an output statement, but I'm honestly not sure how to find the min, median, mean, and max using proc univariate. Any help would be appreciated. 4. Use a procedure to create summary statistics for the working...

  • Simple R programming question: I need to download this data set from kaggle, what is the...

    Simple R programming question: I need to download this data set from kaggle, what is the correct code? the one that I am using is not working: library(data.table) boston_variable <- read.csv("https://www.kaggle.com/rojour/finishers-boston-marathon-2017#marathon_results_2017.csv") returns: Version:1.0 StartHTML:0000000107 EndHTML:0000000950 StartFragment:0000000127 EndFragment:0000000932 cannot open URL 'https://www.kaggle.com/rojour/finishers-boston-marathon-2017#marathon_results_2017.csv': HTTP status was '404 Not Found

  • Please ignore the circled choices. I am double checking my work. ame rangs, then what must...

    Please ignore the circled choices. I am double checking my work. ame rangs, then what must be a) their high and low data valoes b) the entire Eistribations () their standard deviacions 0) the difference betweem their high and lew data values e) their means 2. nkewed distribution, the median is peefenred over the mean as a measure of the center becaune he median is less than the mean d) the men menures the spread in the data modian measures...

  • I have a data set called ACS that I set my_data <- read.csv('acs_ny_CSV.csv'). One of the...

    I have a data set called ACS that I set my_data <- read.csv('acs_ny_CSV.csv'). One of the values in the data set here is FamilyIncome having a value from 50 to 1 mill plus FamilyIncome Min. : 50 1st Qu.: 52540 Median : 87000 Mean : 110281 3rd Qu.: 133800 Max. :1605000 I need to convert this value to a 0 and 1 as I need to "Make a binary variable with value TRUE for income above $150,000 and FALSE for...

  • In this scenario, I am going to place you in a situation where you need to...

    In this scenario, I am going to place you in a situation where you need to advise a client on an advertising decision and provide a rationale for your decision. Scenario #1: A catering company is planning to advertise its services to businesses in an area. It wants to use an advertising medium which is low to moderate in cost and moderate to high in audience selectivity. What do you recommend? Other recommendations than social media Please respond in 200-250...

  • I need help with getting these SQL codes please, I can run them myself. I just need the codes Create a risk ranking of returned items in 2014. Create a new column of data that shows whether something...

    I need help with getting these SQL codes please, I can run them myself. I just need the codes Create a risk ranking of returned items in 2014. Create a new column of data that shows whether something is high risk, medium risk or low risk based on the following criteria. If the return was equal to or more than $1,000, it is high risk; if the return is equal to or more than $500 and less than $1,000, it...

  • [USING RSTUDIO] I am having trouble already in step 3 of number 1. Im not sure...

    [USING RSTUDIO] I am having trouble already in step 3 of number 1. Im not sure why what I typed isn't working. I appreciate anybody that can help me out. Thanks 1. Recall the `iris` data set from last week's exercise. The `iris` data set is already pre-loaded in R - look at the help file using `?iris` for more information on this data set.    i) Check the structure of the data using the function `str(iris)`.    ii) Find...

  • Working on a program where my task is to implement a library (as a set of...

    Working on a program where my task is to implement a library (as a set of source and header files, documentation, and a Makefile) that provides a few useful functions for working with a counted string data structure. And one of the functions that needs to be written is described below but I am having a little difficulty writing it. Program needs to be written in C. Struct: typedef struct {    char *data;    size_t length; } kstring; function:...

  • I need help doing this practice exercise in Scratch. I am not sure where to start...

    I need help doing this practice exercise in Scratch. I am not sure where to start Your task is to make a Scratch program that will tell you the letter grade based on the percentage. 1. Create a variable grade (have grade display as a scroll bar). 2. When the green flag is clicked, the program should look at the value of the grade and the Sprite should respond with a letter as follows: A: greater than 89 B: greater...

  • Appreciate if you can answer this ONE QUESTION COMPLETELY and give me a detailed working with...

    Appreciate if you can answer this ONE QUESTION COMPLETELY and give me a detailed working with explanation for me to understand. Once completed so long as my doubts are cleared and the solutions are correct, I will definitely vote up. Some of the question are similiar to take a look carefully before you answer as it's very important for me. Thank you. Question 5 The management team of a US-based airline is considering making changes to its checked-in baggage allowance...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT