Question: Please use routines from base R. Create the following data frame called data. With respect to variables x1, x3 and x4, please use sequences. Finally,

  1. Please use routines from base R.

    1. Create the following data frame called data. With respect to variables x1, x3 and x4, please use sequences. Finally, check the data structure and data types of data.

 Please use routines from base R. Create the following data frame

  1. Create a new binary (1 or 0) variable x5 that is part of data object "data". Assign value 1 to x5 if values of variable x2 are equal or greater than 100 AND less than 200 AND if x4 does not equal 2020. Otherwise, assign 0 to x5.

  2. Please cut the numeric variable x2 into a new ordinal variable x6 with following three categories (breaks): (0-200], [201-300], [301-400]. You may use the cut-function. Check if x6 is really an ordinal variable.

  3. Replace the value of second and fifth observation (rows) of variable x1 by value 20.

  4. Replace the value of variable x4 by 2018 if x5 equals 1 OR if x2 is equal or less 150.

  5. Drop variables x3, x5 and store selection in new data object data2.

  6. Rename the variables of data2 the following: x1 = age, x2 = income, x4 = year, x6 = income_bracket.

  7. Given the data object data2, please re-arrange the variables into following order: year, age, income, income_bracket.

  8. Sort data2 by multiple columns. Sort first by income and then by age, both variables in descending order.

x1 x2 x3 X4 1 25 278 A 2019 2 27 113 B 2019 3 29 294 C 2019 4 31 217 D 2019 5 33 398 E 2020 6 35 328 F 2020 7 37 343 G 2020 8 39 113 H 2020 9 41 2521 2021 10 43 189) 2021

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!