## Header --------------------------- ## Script name: Instron Sample Averaging ## Purpose of script: Create an averaged dataset for the displacement/force for each textile ## Author: Eric Beaudette ## ## Date Created: November 1st, 2022 ## Last Modified: October 12th, 2024 ## ## Email: beaud128@umn.edu ## Set Up ------------- setwd("/Users/ericbeaudette/Desktop/DRUM Records/Compression Modelling - Tensile Testing Data/Raw Data") library(ggplot2) library(scales) library(data.table) ## Sample Upload ---- Sample1 <- read.csv(file= "T1 1L C 1.csv", header=TRUE) Sample1 <- Sample1[-1,] Sample1 <- Sample1[,c(-4,-5)] Sample1$Displacement <- as.numeric(Sample1$Displacement) Sample1$Force <- as.numeric(Sample1$Force) Sample2 <- read.csv(file= "T1 1L C 2.csv", header=TRUE) Sample2 <- Sample2[-1,] Sample2 <- Sample2[,c(-4,-5)] Sample2$Displacement <- as.numeric(Sample2$Displacement) Sample2$Force <- as.numeric(Sample2$Force) Sample3 <- read.csv(file= "T1 1L C 3.csv", header=TRUE) Sample3 <- Sample3[-1,] Sample3 <- Sample3[,c(-4,-5)] Sample3$Displacement <- as.numeric(Sample3$Displacement) Sample3$Force <- as.numeric(Sample3$Force) Sample4 <- read.csv(file= "T1 1L C 4.csv", header=TRUE) Sample4 <- Sample4[-1,] Sample4 <- Sample4[,c(-4,-5)] Sample4$Displacement <- as.numeric(Sample4$Displacement) Sample4$Force <- as.numeric(Sample4$Force) Sample5 <- read.csv(file= "T1 1L C 5.csv", header=TRUE) Sample5 <- Sample5[-1,] Sample5 <- Sample5[,c(-4,-5)] Sample5$Displacement <- as.numeric(Sample5$Displacement) Sample5$Force <- as.numeric(Sample5$Force) ## Quick Visualization ---- ggplot()+ geom_point(data = Sample1, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample2, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample3, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample4, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample5, aes(x=Displacement, y= Force), col="grey")+ xlim(0,500)+ ylim(0,100) ## Start and Stop for Grouping ---- # Data is trimmed based on the highest minimum strain and the lowest maximum strain to ensure there is data from all five samples start<- ceiling(as.numeric( max(c(Sample1[1,2],Sample2[1,2],Sample3[1,2],Sample4[1,2],Sample5[1,2])))) stop <- floor(as.numeric(min(c(Sample1[nrow(Sample1),2],Sample2[nrow(Sample2),2],Sample3[nrow(Sample3),2],Sample4[nrow(Sample4),2],Sample5[nrow(Sample5),2])))) avgfile <- data.frame(matrix(nrow=1, ncol=3) ) row <- 1 range<- stop-start ## Merging Loop ---- for (i in (0:(range*4))){ lowlim <- start + (i/4) highlim<- start + (i/4) + .25 x<- rbindlist(list(subset(Sample1, ((Displacement>=lowlim) & (Displacement < highlim))), subset(Sample2, ((Displacement>=lowlim) & (Displacement < highlim))), subset(Sample3, ((Displacement>=lowlim) & (Displacement < highlim))), subset(Sample4, ((Displacement>=lowlim) & (Displacement < highlim))), subset(Sample5, ((Displacement>=lowlim) & (Displacement < highlim))) ) ) avgfile[row,1] <- (lowlim+highlim) / 2 avgfile[row,2] <- mean(x$Force) avgfile[row,3] <- sd(x$Force) row <- row +1 } colnames(avgfile)<- c("Displacement","Force","SDForce") ## Visualization - Post Average ggplot()+ geom_point(data = Sample1, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample2, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample3, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample4, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = Sample5, aes(x=Displacement, y= Force), col="grey")+ geom_point(data = avgfile, aes(x=Displacement, y= Force), col="red")+ xlim(0,500)+ ylim(0,100) write.csv(avgfile, file = "T1 1L C AVG.csv", row.names = FALSE)