Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

These questions use R. Any help is greatly appreciated and the relevant code wou

ID: 3313225 • Letter: T

Question

These questions use R. Any help is greatly appreciated and the relevant code would be very helpful as well. Adding Columns: There are several ways to do this. The first is to create a variable name for the new column and attach it to the data frame with its value. For example, suppose you wanted to create a new column in the data frame "datatrame" and call it "oewColumn". It is the sum of two old columns. You could use the following code: dataPrame$01dColumn1 + dataFrame$01dColumn2 4. add a column called "margin", which is the profit For the data frame SompaniesDat divided by the revenue, quantity times 100 5. Create the column again, this time using the "round" function to round the number of decimal places of margin to 2. Transform function: Another way to add a column that is a function to two other columns is the "transform" function. We can do the same thing that we did above with the following code 6. Type the code that you would use to add the column margin using the transform function. Round your margin to the nearest hundredth's place. Bonus if you can do it all in one line! Apply Function: We have used the apply function in class. Run this piece of code and explain what it does. This code assumes that you have been using the same variable names and capitalization structures in your code as I have been using above: 7. 1, function (x) (x [2]/x [1]) 100 ) The mapply format to create a new column in a data frame is dataFrame$column2, dataFrame$column3) In the above example, mapply applies the function "sometunction" to the first three columns of the data frame “dataframe. Note that the first argument to mapply is the name of a function. That function can be a built in R function or one that you create.

Explanation / Answer


4
companiesData$margin <- (companiesData$profit/companiesData$revenue)*100

5

companiesData$margin <- round((companiesData$profit/companiesData$revenue)*100,2)

6
companiesData <- transform(companiesData,margin= round((companiesData$profit/companiesData$revenue)*100,2))


Please note that we can answer only 1 question at a time , i have answered 3 .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote