From 9ef1ee30dcf1b8bfc5d813c25ae445e803b9e5d5 Mon Sep 17 00:00:00 2001 From: GreatnessTheEyenor Date: Mon, 20 Oct 2025 15:27:30 +0100 Subject: [PATCH 1/3] Add files via upload --- Completed Programming Assignment 2.R | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Completed Programming Assignment 2.R diff --git a/Completed Programming Assignment 2.R b/Completed Programming Assignment 2.R new file mode 100644 index 00000000000..887750f9558 --- /dev/null +++ b/Completed Programming Assignment 2.R @@ -0,0 +1,43 @@ +## This function creates a special "matrix" object that can cache its inverse. +makeCacheMatrix <- function(x = matrix()) { + inv <- NULL # Initialize the inverse as NULL + + # Setter function to update the matrix + set <- function(y) { + x <<- y + inv <<- NULL # Reset inverse when a new matrix is set + } + + # Getter function to return the matrix + get <- function() x + + # Setter function for the inverse + setInverse <- function(inverse) inv <<- inverse + + # Getter function for the inverse + getInverse <- function() inv + + # Return a list containing all four functions + list(set = set, get = get, + setInverse = setInverse, + getInverse = getInverse) +} + + +## This function computes the inverse of the special matrix returned by makeCacheMatrix above. +## If the inverse has already been calculated, it retrieves it from the cache instead of recomputing. +cacheSolve <- function(x, ...) { + inv <- x$getInverse() + + # Check if inverse already exists + if (!is.null(inv)) { + message("Getting cached inverse") + return(inv) + } + + # Otherwise, calculate the inverse + mat <- x$get() + inv <- solve(mat, ...) # Compute the inverse using R's 'solve' function + x$setInverse(inv) # Cache the inverse for later use + inv # Return the computed inverse +} From 3961bf1b7a85f5d9f1d0222b47aa9ed7e50b5fd4 Mon Sep 17 00:00:00 2001 From: GreatnessTheEyenor Date: Tue, 11 Nov 2025 14:05:21 +0100 Subject: [PATCH 2/3] Add files via upload --- assigment3.R | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 assigment3.R diff --git a/assigment3.R b/assigment3.R new file mode 100644 index 00000000000..0f92454991e --- /dev/null +++ b/assigment3.R @@ -0,0 +1,66 @@ +setwd("C:\Users\xps\Downloads\getdata_projectfiles_UCI HAR Dataset") +# =============================================================== +# run_analysis.R +# Course Project: Getting and Cleaning Data +# Author: +# =============================================================== + +# STEP 0: Load required library +library(dplyr) # Install first if not installed: install.packages("dplyr") + +# STEP 1: Read all the data files --------------------------------------------- + +# Read feature names and activity labels +features <- read.table("features.txt", col.names = c("index", "feature")) +activities <- read.table("activity_labels.txt", col.names = c("code", "activity")) + +# Read training data +x_train <- read.table("train/X_train.txt", col.names = features$feature) +y_train <- read.table("train/y_train.txt", col.names = "code") +subject_train <- read.table("train/subject_train.txt", col.names = "subject") + +# Read test data +x_test <- read.table("test/X_test.txt", col.names = features$feature) +y_test <- read.table("test/y_test.txt", col.names = "code") +subject_test <- read.table("test/subject_test.txt", col.names = "subject") + +# STEP 2: Merge training and test sets ---------------------------------------- + +X <- rbind(x_train, x_test) # Combine measurement data +Y <- rbind(y_train, y_test) # Combine activity codes +Subject <- rbind(subject_train, subject_test) # Combine subjects +merged_data <- cbind(Subject, Y, X) # Merge all into one dataset + +# STEP 3: Extract only mean and standard deviation columns -------------------- + +tidy_data <- merged_data %>% + select(subject, code, contains("mean"), contains("std")) + +# STEP 4: Replace activity codes with descriptive activity names -------------- + +tidy_data$code <- activities[tidy_data$code, 2] +names(tidy_data)[2] <- "activity" + +# STEP 5: Rename variable names with descriptive names ------------------------ + +names(tidy_data) <- gsub("^t", "Time", names(tidy_data)) +names(tidy_data) <- gsub("^f", "Frequency", names(tidy_data)) +names(tidy_data) <- gsub("Acc", "Accelerometer", names(tidy_data)) +names(tidy_data) <- gsub("Gyro", "Gyroscope", names(tidy_data)) +names(tidy_data) <- gsub("Mag", "Magnitude", names(tidy_data)) +names(tidy_data) <- gsub("BodyBody", "Body", names(tidy_data)) + +# STEP 6: Create a tidy dataset with the average of each variable ------------- +# for each activity and each subject + +final_data <- tidy_data %>% + group_by(subject, activity) %>% + summarise_all(mean) + +# STEP 7: Write the final tidy dataset to a text file ------------------------- + +write.table(final_data, "tidy_dataset.txt", row.name = FALSE) + +# Done! ---------------------------------------------------------------------- +cat("Tidy dataset created and saved as 'tidy_dataset.txt' in your working directory.\n") + From 9467e27ef4472642e0e4810ccfad20e458999b5b Mon Sep 17 00:00:00 2001 From: GreatnessTheEyenor Date: Tue, 11 Nov 2025 14:25:43 +0100 Subject: [PATCH 3/3] Delete assigment3.R --- assigment3.R | 66 ---------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 assigment3.R diff --git a/assigment3.R b/assigment3.R deleted file mode 100644 index 0f92454991e..00000000000 --- a/assigment3.R +++ /dev/null @@ -1,66 +0,0 @@ -setwd("C:\Users\xps\Downloads\getdata_projectfiles_UCI HAR Dataset") -# =============================================================== -# run_analysis.R -# Course Project: Getting and Cleaning Data -# Author: -# =============================================================== - -# STEP 0: Load required library -library(dplyr) # Install first if not installed: install.packages("dplyr") - -# STEP 1: Read all the data files --------------------------------------------- - -# Read feature names and activity labels -features <- read.table("features.txt", col.names = c("index", "feature")) -activities <- read.table("activity_labels.txt", col.names = c("code", "activity")) - -# Read training data -x_train <- read.table("train/X_train.txt", col.names = features$feature) -y_train <- read.table("train/y_train.txt", col.names = "code") -subject_train <- read.table("train/subject_train.txt", col.names = "subject") - -# Read test data -x_test <- read.table("test/X_test.txt", col.names = features$feature) -y_test <- read.table("test/y_test.txt", col.names = "code") -subject_test <- read.table("test/subject_test.txt", col.names = "subject") - -# STEP 2: Merge training and test sets ---------------------------------------- - -X <- rbind(x_train, x_test) # Combine measurement data -Y <- rbind(y_train, y_test) # Combine activity codes -Subject <- rbind(subject_train, subject_test) # Combine subjects -merged_data <- cbind(Subject, Y, X) # Merge all into one dataset - -# STEP 3: Extract only mean and standard deviation columns -------------------- - -tidy_data <- merged_data %>% - select(subject, code, contains("mean"), contains("std")) - -# STEP 4: Replace activity codes with descriptive activity names -------------- - -tidy_data$code <- activities[tidy_data$code, 2] -names(tidy_data)[2] <- "activity" - -# STEP 5: Rename variable names with descriptive names ------------------------ - -names(tidy_data) <- gsub("^t", "Time", names(tidy_data)) -names(tidy_data) <- gsub("^f", "Frequency", names(tidy_data)) -names(tidy_data) <- gsub("Acc", "Accelerometer", names(tidy_data)) -names(tidy_data) <- gsub("Gyro", "Gyroscope", names(tidy_data)) -names(tidy_data) <- gsub("Mag", "Magnitude", names(tidy_data)) -names(tidy_data) <- gsub("BodyBody", "Body", names(tidy_data)) - -# STEP 6: Create a tidy dataset with the average of each variable ------------- -# for each activity and each subject - -final_data <- tidy_data %>% - group_by(subject, activity) %>% - summarise_all(mean) - -# STEP 7: Write the final tidy dataset to a text file ------------------------- - -write.table(final_data, "tidy_dataset.txt", row.name = FALSE) - -# Done! ---------------------------------------------------------------------- -cat("Tidy dataset created and saved as 'tidy_dataset.txt' in your working directory.\n") -