Question & Answer: setwd("C:/COM337_R_Programming2017Q2/COM337 exam/ExamStarterKit/Q22017_Question#1")…..

R PROGRAMMING USING R STUDIO

THIS IS THE INPUT IN NOTEPAD

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: setwd("C:/COM337_R_Programming2017Q2/COM337 exam/ExamStarterKit/Q22017_Question#1")…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

SYMBOL,DATE,SP
GOOG,2017-03-01,829
APPL,2017-03-01,143
MSFT,2017-03-01,65
GOOG,2017-02-01,823
APPL,2017-02-01,136
MSFT,2017-02-01,63
GOOG,2017-01-03,796
APPL,2017-01-03,120
MSFT,2017-01-03,64
GOOG,2016-12-01,771
APPL,2016-12-01,115
MSFT,2016-12-01,61
GOOG,2016-11-01,758
APPL,2016-11-01,110
MSFT,2016-11-01,59
GOOG,2016-10-03,784
APPL,2016-10-03,112
MSFT,2016-10-03,59
GOOG,2016-09-01,777
APPL,2016-09-01,111
MSFT,2016-09-01,56
GOOG,2016-08-01,767
APPL,2016-08-01,105
MSFT,2016-08-01,56
GOOG,2016-07-01,768
APPL,2016-07-01,102
MSFT,2016-07-01,55
GOOG,2016-06-01,692
APPL,2016-06-01,94
MSFT,2016-06-01,50
GOOG,2016-05-02,735
APPL,2016-05-02,98
MSFT,2016-05-02,52
GOOG,2016-04-04,693
APPL,2016-04-04,91
MSFT,2016-04-04,48

a s a rerata axe COM337. D com27. | A com337. A coMB7D MODULE | Q COMB37. A coM37. | A con337. A week so | A COM337. 0 com 37 A COM x + V fileICUsers/AISIAZOUSANDesktop/COM33720t ExanslatteriCOM317-ExarnPaper-August2017-1220Cape Case20study:20liardoutpel t = A 1 ... 3 of 45 Case Study Task Specification You are REQUIRED to use for-each loop from 1 to length (vector of unique symbols), subset (), sum (), length (), range (), Inside the loop, you are expected i, Create (BEFORE THE LOOP) a variable averageStockPriceDF <. vector of Symbol, MaxDate , AverageSP, MinSP , MaxSP as DF (data Frame) header ii. Calculate The minimum and maximum SP (for each unique symbol) however you cannot use the mini ) and max ) functions; then use printſ) to display your values. ii, Calculate the average SP (for each unique symbol), however you cannot use the mean () function to do this; then use print () to display you computed value. iv. Calculate the latest SP date (for each unique symbolusing maxDate <. max (as. Date (subset of topDogVizDFSDATE where topDog VizDFSSYMBOL= unique sysmbol; then use print () to display the maxDate. Continued overleaf ... Page 3 of 45 a a a de R ENG 12/08/2011 1130Question & Answer: setwd("C:/COM337_R_Programming2017Q2/COM337 exam/ExamStarterKit/Q22017_Question#1")..... 1

##START HERE

setwd(“C:/COM337_R_Programming2017Q2/COM337 exam/ExamStarterKit/Q22017_Question#1”)
topDogVizDF <- read.csv(“InputChallenge#2BV2.txt”)
head(topDogVizDF,10)
tail(topDogVizDF)

##Solution

a s a rerata axe COM337. D com27. | A com337. A coMB7D MODULE | Q COMB37. A coM37. | A con337. A week so | A COM337. 0 com 37 A COM x + V fileICUsers/AISIAZOUSANDesktop/COM33720t ExanslatteriCOM317-ExarnPaper-August2017-1220Cape Case20study:20liardoutpel t = A 1 … 3 of 45 Case Study Task Specification You are REQUIRED to use for-each loop from 1 to length (vector of unique symbols), subset (), sum (), length (), range (), Inside the loop, you are expected i, Create (BEFORE THE LOOP) a variable averageStockPriceDF

Expert Answer

 

setwd(“C:/COM337_R_Programming2017Q2/COM337 exam/ExamStarterKit/Q22017_Question#1”)
topDogVizDF <- read.csv(“InputChallenge#2BV2.txt”)
topDogVizDF$DATE <- as.Date(topDogVizDF$DATE)

averageStockPriceDF <- data.frame(“Symbol”=character(),
“MaxDate”=as.Date(character()),
“AverageSP”=numeric(), “MinSP”=numeric(), “MaxSP”=numeric())

by <- topDogVizDF$SYMBOL

for(i in 1:length(unique(by))){
sub.topDogVizDF <- topDogVizDF[by==unique(by)[i],]
minSP <- sub.topDogVizDF$SP[1]
maxSP <- sub.topDogVizDF$SP[1]
avgSP <- sub.topDogVizDF$SP[1]

for(j in 2:nrow(sub.topDogVizDF)){
if (minSP > sub.topDogVizDF$SP[j]){
minSP <- sub.topDogVizDF$SP[j]
}

if(maxSP < sub.topDogVizDF$SP[j]){
maxSP <- sub.topDogVizDF$SP[j]
}

avgSP <- avgSP + sub.topDogVizDF$SP[j]
}

avgSP <- avgSP/nrow(sub.topDogVizDF)
print(paste(by[i], paste(“MINSP = “, minSP)))
print(paste(by[i], paste(“MAXSP = “, maxSP)))
print(paste(by[i], paste(“AVGSP = “, avgSP)))

maxDt <- max(sub.topDogVizDF$DATE)

averageSP_record <- data.frame(“Symbol”=by[i],
“MaxDate”=maxDt,
“AverageSP”=avgSP,
“MinSP”=minSP,
“MaxSP”=maxSP)
print(paste(by[i], paste(“MAXDATE = “, averageSP_record$MaxDate)))
#print(averageSP_record)
averageStockPriceDF<- data.frame(rbind(as.matrix(averageStockPriceDF), as.matrix(averageSP_record)))
}

write.csv(averageStockPriceDF, “AverageStockPrice.txt”, row.names = FALSE, col.names = FALSE, sep=”.”)

topDocAverageSP <- read.csv(“AverageStockPrice.txt”)
print(paste(“ROWS topDocAverageSP= “, nrow(topDocAverageSP)))
print(paste(“COLS topDocAverageSP= “, ncol(topDocAverageSP)))

Still stressed from student homework?
Get quality assistance from academic writers!