NOTE: THIS IS R PROGRAMMING: Discuss how to solve the following problems use R c
ID: 3773785 • Letter: N
Question
NOTE: THIS IS R PROGRAMMING: Discuss how to solve the following problems use R code. You’re not just writing the R code, you are also discussing the process.
Considering the following data frame called items (note the row names and column names):
store id
item name
price
entry 1
1
milk
$1.99
entry 2
2
egg
$0.99
entry 3
3
fish
$1.99
entry 4
4
pork
$3.99
entry 5
5
beef
$4.99
Write R code(s) to:
retrieve all the information for entry2;
Retrieve all the item names;
Use two ways to retrieve beef;
Retrieve the item name and price columns for store id greater than 3.
The resulting data frame for (d) should look like below.
item name
price
entry 4
pork
$3.99
entry 5
beef
$4.99
Considering this function header:
myFun=function(first=10,second=20,third=30,fourth=40), List the values of first,
second, third, and fourth when we call myFun in the following ways.
myFun()
myFun(second=60,70)
myFun(fourth=10,first=20,50,80)
store id
item name
price
entry 1
1
milk
$1.99
entry 2
2
egg
$0.99
entry 3
3
fish
$1.99
entry 4
4
pork
$3.99
entry 5
5
beef
$4.99
Explanation / Answer
item <- data.frame(
store_id = c(1:5),
item_name = c("milk","egg","fish","pork","beef"),
price = c(1.99,0.99,1.99,3.99,4.99),
stringsAsFactors=FALSE
)
# retrieve all the information for entry2;
result <- emp.data[2]
print (result)
# Retrieve all the item names;
result <- data.frame(item$item_name)
print(result)
# Use two ways to retrieve beef;
# 1st way
item
# 2nd way
result <- data.frame(item$store_id,item$item_name,item$price)
print(result)
# Retrieve the item name and price columns for store id greater than 3
result <- data.frame(ifelse(item$store_id > 3, (item$item_name,item$price), NA))
print result
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.