Keenan Exercise 10 Submission#2
Conversation
| #put in start score of 0-0 | ||
| uw<-rbind(uw, first_entry) | ||
| msu<-rbind(msu, first_entry) | ||
|
|
There was a problem hiding this comment.
or you can do something like the code below. This code is equivalent to from line 9 to 18:
uw <- data.frame(time = 0, score = 0)
msu <- data.frame(time = 0, score = 0)
| names(final_entry_uw)<- c('time', 'score') | ||
| uw<-rbind(uw, final_entry_uw) | ||
| msu<-rbind(msu, final_entry_msu) | ||
|
|
There was a problem hiding this comment.
A different approach that is more efficient. You don't need to use rbind every time:
load table of scoring
scoring=read.table("UWvMSU_1-22-13.txt",header=TRUE,sep="\t",stringsAsFactors=FALSE)
look at data
dim(scoring)
head(scoring)
preallocating matrix to store cumulative scores
cum_scores=matrix(NA,nrow(scoring)+1,3)
cum_scores[,1]=c(0,scoring[,1])
cum_scores[1,2:3]=0
colnames(cum_scores)=c("time","UW","MSU")
looping through individual scoring events
for(i in 1:nrow(scoring)){
if(scoring[i,2]=="UW"){
cum_scores[(i+1),2]=cum_scores[i,2]+scoring[i,3]
cum_scores[(i+1),3]=cum_scores[i,3]
}else{
cum_scores[(i+1),2]=cum_scores[i,2]
cum_scores[(i+1),3]=cum_scores[i,3]+scoring[i,3]
}
}
| ggplot(data=msu, aes(x=time, y=score), color='green') + | ||
| geom_line() + | ||
| geom_line(data=uw, aes(x=time, y=score), color='red') | ||
|
|
There was a problem hiding this comment.
You can plot this in a combined data in ggplot as well:
ggplot(data=cum_scores, aes(x=time)) +
geom_line(aes(x=time, y=MSU), color='green') +
geom_line(aes(x=time, y=UW), color='red')
There was a problem hiding this comment.
oops, sr, it should be:
ggplot(data=cum_scores, aes(x=time)) +
geom_line(aes(y=MSU), color='green') +
geom_line(aes(y=UW), color='red')
No description provided.