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

setwd(\"C:/COM337_R_Programming2017Q2/BabyStep\") mydata <- read.csv(\"NCC2015Op

ID: 3856052 • Letter: S

Question

setwd("C:/COM337_R_Programming2017Q2/BabyStep")
mydata <- read.csv("NCC2015OperatorData(Edited).txt")
##
##Create a duplicate ofmydata
myDataUpdated <- mydata

##Create operator only data slice
operatorDataSlice <- mydata[1]
operatorDataSlice
str(operatorDataSlice)

##create change in quarter 4
changeInQtr4 <- mydata$Dec.15 - mydata$Sep.15
changeInQtr4
str(changeInQtr4)

##One of the way to add new col to data frame (DF)
##use the transform function
##transform() does not change original DF
##Note:newColName can be any Name we want
newDataFrame <- transform(mydataUpdated,
newColName = changeInQtr4
)
newDataFrame

##Another way to add new col to Data frame
##use with, but this changes original DF
##Here we use the $ to add new column name
##In this case new col name is "changeInQtr4"
myDataUpdated$changeInQtr4 <- with(myDataUpdated, changeInQtr4)
myDataUpdated

##Re-create #2 duplicate of mydataFrame
myDataUpdated <- mydata
##using col number notation, this overwrites DF

newDF <- transform(myDataUpdated,
changeInQtr4=(mydataUpdated[1:4,5]-mydataUpdated[1:4,4]))

newDF

##Re-create #2 duplicate of mydataFrame
myDataUpdated <- mydata
##using col number notation

myDataUpdated$changeInQtr4 <- with(myDataUpdated,
(mydataUpdated[1:4,5]-mydataUpdated[1:4,4]))
##[Step A]
##using eric's solution
##find change in Dec-15 versus Sept-15
Qtr4Change<-mydataUpdated[5] - myDataUpdated[4]
Qtr4Change

##[Step B]
##Add two columns to form new frame
operatorCountChangeQrt4 <-data.fram(mydataUpdated[1],Qtr4Change)
operatorCountChangeQrt4
##using Eric construct to change col name
names(operatorCountChangeQrt4)[2]<- paste("changeQtr4")
operatorCountChangeQrt4


##start prep for barplot()
##calculate ratio of change in quarter 4
qtr4Percentchange <-(operatorCountChangeQrt4[1:4,2]/mydata[1:4,4]*100)
qtr4Percentchange
str(qtr4Percentchange)

##combine ratio to creat DF showing charge change and ratio
operatorPLusChangeplusRatio <- data.frame(mydataUpdated[1],
Qtr4Change,qtr4Percentchange)
operatorPLusChangeplusRatio

##so, to show change we use barplot
##plot bar plot itself


##Add name to qtr percent change vector
names(qtr4Percentchange) <- operatorDataSlice$OperatorName
qtr4Percentchange
str(qtr4Percentchange) ##this is a name a vector
##Natsy plot with operatorName
barplot(qtr4Percentchange) ##**bad name display
##let us fix the name using a custom function
##create an operator vector
operatorVector <- operatorDataSlice$OperatorName
operatorVector
str(operatorVector)
##use function to abbreviate operator name
##insert function code(start)
nameConverter <- function(operatorName, counter)
{
shortName <- operatorName
if(grepl("MTN",operatorName,ignore.case = TRUE)){
shortName<-"MTN"
}
if(grepl("GLO",operatorName,ignore.case = TRUE)){
shortName<-"GLO"
}
if(grepl("Airtel",operatorName,ignore.case = TRUE)){
shortName<-"AIRTEL"
}
if(grepl("EMTS", operatorName,ignore.case = TRUE)){
shortName<-"ETISALAT"
}
return(shortName)
}


abreviatedName <- NULL
for(loopLounter in (1:length(operatorVector)))
{
shortName<- nameConverter(operatorVector[loopLounter],
loopLounter)
abreviatedName <-c(abreviatedName,shortName)
print(abreviatedName)
}
abreviatedName


##write.table(newHeaderAlternate, "convertedHeaderAlternate.csv", row.names = FALSE,na="",
##col.names = FALSE, quote = FALSE)

header <- colnames(mydata)
x<-1:nrow(mydata)
## create row one by one with loop
for (outer in(1:nrow(mydata))){
myRow <-mydata[outer, 1:ncol(mydata)]
  
shortName<- nameConverter(operatorVector[outer],
outer)
abreviatedName <-c(abreviatedName,shortName)
  
g <- myRow[1,1]
g
  
##inner loop
for (inner in 2:ncol(myRow))
{
operatorCount <- myRow[1,inner]


print(paste(shortName,operatorCount,sep="|"))
  
  
}
}

WE ARE SUPPOSED TO USE THE ABOVE CODE TO SOLVE THE PROBLEM IN THIS IMAGE. THE FUNCTION TO CHANGE THE NAME (I.E FROM 'AIRTEL' TO 'AIR, 'ETISALAT' TO 'ETI') HAS BEEN GIVEN, WE NEED TO USE IT TO CONVERT IT, ALSO WE ARE SUPPOSED TO USE FOR LOOP TO CHANGE THE FORMAT OF THE DATE, AS SHOWN IN THE ABOVE IMAGE. THE GENERAL CONCCEPT OF THE PROBLEM IS, "mydata" IS GIVEN TO US IN AN EXCEL FILE, AND SINCE I CANT INSERT IT HERE YOU HAVE TO CREATE IT YOURSELF PLEASE, WITHOUT USING 'RESHAPE', WE ARE MEANT TO CHANGE THE FORMAT OF THE EXCEL DATA TO THE ABOVE GIVEN SUBSCRIBERCOUNT.TXT FORMART

THIS IS THE FUNCTION WE ARE TO USE TO CONVERT THE NAMES

Starting with a R-script named Week8_TakeHome_Quiz provide the code to solve the following problem Given our data frame > mydata 1 MTN Nigeria communications 61149397 62813111 Globacom Limited 29577125 31256677 Airtel Nigeria 28680757 29564766 4 EMTS Limited (Etisalat) 22235557 22852232 OperatorName March2015 June2015 September2015 December2015 61252387 32999384 32268301 22161290 62493732 31306472 1134625 23492214 Write the code to process this data frame to create another data frame named SubscriberCount which you must write to a file named SubscriberCount.bt X rator, Quarter, Count MTN, Mar-15, 61149397 MTN, Jun-15, 62813111 MTN, Sep-15, 62493732 MTN, Dec-15, 61252387 GLO, Mar-15, 29577125 GLO, Jun-15, 31256677 GLO, Sep-15, 31306472 GLO, Dec-15,32999384 AIRTEL, Mar-15,28680757 AIRTEL, Jun-15,29564766 AIRTEL, Sep-15, 31134625 AIRTEL,Dec-15, 32268301 ETISALAT, Mar-15, 22235557 ETISALAT, Jun-15,22852232 ETISALAT, Sep-15,23492214 ETISALAT, Dec-15,22161290 However before generating this data frame, use a custom function to change the long operator name to the short name as shown and to achieve the following transformations: Mar-15-2015-03 June-15->2015-06 Sep-15->2015-09 Dec-15 -2015-12 Use the write.table() function shown on Page 25 to create the file named SubscriberCount.txt with converted as shown but after the indicated transformations have been applied Oops! The Conversion for Airtel should be "AIR" and Etisalat should be "ETI” COM337 R-Programming-Week 8 (Part-B): E.U.Kvac Page 41

Explanation / Answer

Inside This Issue: Editor: Patrick A. Townson Book Review: "CDMA: Principles of Spread Spectrum Communication" (R. Slade) Billing Goofups (Gary Novosielski) Convert DID Voice System to ISDN BRI Voice System (Rick Strobel) CFP: 4th UK/Australian Int. Symposium on DSP (Tadeusz Wysocki) Telecommunications Short Courses (Bill Bond) TELECOM Digest is an electronic journal devoted mostly but not exclusively to telecommunications topics. It is circulated anywhere there is email, in addition to various telecom forums on a variety of public service systems and networks including Compuserve and America On Line. It is also gatewayed to Usenet where it appears as the moderated newsgroup 'comp.dcom.telecom'. Subscriptions are available to qualified organizations and individual readers. Write and tell us how you qualify: * telecom-request@eecs.nwu.edu * The Digest is edited, published and compilation-copyrighted by Patrick Townson of Skokie, Illinois USA. You can reach us by postal mail, fax or phone at: 9457-D Niles Center Road Skokie, IL USA 60076 Phone: 500-677-1616 Fax: 708-329-0572 ** Article submission address only: telecom@eecs.nwu.edu ** Our archives are located at lcs.mit.edu and are available by using anonymous ftp. The archives can also be accessed using our email information service. For a copy of a helpful file explaining how to use the information service, just ask.