Skip to content

ShannonCulbert_Exercise10_Submission#10

Open
shanculbert wants to merge 1 commit into
qtran4:mainfrom
shanculbert:main
Open

ShannonCulbert_Exercise10_Submission#10
shanculbert wants to merge 1 commit into
qtran4:mainfrom
shanculbert:main

Conversation

@shanculbert
Copy link
Copy Markdown

No description provided.

Comment thread Culbert_Exercise10.R
#cumulative sums
UW_MSU$UW_Total <- c(cumsum(UW_score))
UW_MSU$MSU_Total <- c(cumsum(MSU_score))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do the cumulative sum within the for loop as well:

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]
}
}

Copy link
Copy Markdown
Owner

@qtran4 qtran4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants