diff --git a/ExtraPractice.R b/ExtraPractice.R new file mode 100644 index 0000000..9644078 --- /dev/null +++ b/ExtraPractice.R @@ -0,0 +1,68 @@ +#Monday Activity: Wage for all males and all females +fwage = 0 +mwage = 0 + +for (i in 1:nrow(wages)){ + if (wages[i,1] == "female"){ + fwage = fwage + wages[i,]$wage + } + else if (wages[i,1] == "male"){ + mwage = mwage + wages[i,]$wage + } + +} + +#DNA Script + +#Initializing Data vectors to empty +sequenceID <- NULL +sequenceLENGTH <- NULL +percentCG <- NULL +meltTEMP <- NULL + +#Reading the File +fileName <- "Lecture11.fasta" +readFile<- file(fileName,open="r") #Makng fileName readable +linn <-readLines(readFile) #Setting linn to the lines of conn + + +#Looping through contents of file +j = 1 +k = 1 +for (i in 1:length(linn)){ + linn_split <- strsplit(linn[i], "")[[1]] #Splits line into series of characters to be accessed + + #Conditional to see if the ith line is a sequence ID + if(linn_split[1] == ">"){ + sequenceID[j] = substring(linn[i],5) + j = j + 1 + + #Calculations for the base pairs + } else { + + #Getting length of sequence + sequenceLENGTH[k] = nchar(linn[i], type = "chars") + + #Calculating percentCG + CG = 0 + for (base in linn_split) { + if (base == "G" || base == "C") { + CG = CG + 1 + } + } + percentCG[k] = CG/sequenceLENGTH[k]*100 + + #Calculating melting temp + if (sequenceLENGTH[k] > 14){ + meltTEMP[k] = -9999 + } else { + meltTEMP[k] = 4*CG + 2*(sequenceLENGTH[k] - CG) + } + + k = k + 1 + } +} +close(readFile) + +#Putting everything into a table called DNA.dat +DNA.dat <- data.frame(sequenceID, sequenceLENGTH, percentCG, meltTEMP) diff --git a/Tutorial5Challenge.R b/Tutorial5Challenge.R new file mode 100644 index 0000000..8702066 --- /dev/null +++ b/Tutorial5Challenge.R @@ -0,0 +1,54 @@ +#Reading in the Data (make sure your working directory is correct) +wages=read.csv(file="wages.csv", header = TRUE, stringsAsFactors = FALSE) +attach(wages) + +#Part 1 +data1 <- wages[order(gender,yearsExperience),] +data1 <- (data1[,1:2]) +UNIQUE <- unique(data1) +write.table(UNIQUE, file = "Tutorial5Output.dat", sep = " ") + +#Part 2 +data2 <- wages[order(wage),] +min.wage <- data2[1,] +max.wage <- data2[nrow(wages),] +bottom = nrow(wages) -9 +top = nrow(wages) +top.10 <- data2[bottom:top,] + +counter = 0 +for (i in 1:10){ + if (top.10[i,]$gender == "female") { + counter = counter + 1 + } +} +print("The person with the lowest wage is") +min.wage[,c(1,2,4)] +print("The person with the highest wage is") +max.wage[,c(1,2,4)] + +print("The number of females in the top 10 earners is") +counter + +#Part 3 +highSchoolWages <- NULL +collegeWages <- NULL + +j = 1 +k = 1 +for (i in 1:nrow(wages)){ + if (wages[i,3] == "12"){ + highSchoolWages[j] = wages [i,4] + j = j+1 + }else if (wages[i,3] == "16"){ + collegeWages[k] = wages[i,4] + k = k+1 + } +} + +print("The minimum wage of a high school graduate is:") +min(highSchoolWages) +print("The minimum wage of a college graduate is:") +min(collegeWages) +print("The difference in these wages is") +min(collegeWages) - min(highSchoolWages) \ No newline at end of file