Assignment Chef icon Assignment Chef
All English tutorials

Programming lesson

Getting Started with R Programming: STAT 311 Assignment 0 Tutorial

Learn how to complete STAT 311 Programming Assignment 0 with this step-by-step guide covering vectors, strings, reading data, fixing code, and creating functions in R.

STAT 311 R programming assignment R vectors R strings R functions row sums R Gradescope submission R script debugging data science homework R for statistics beginner R tutorial R code fix sample data R R assignment help

Introduction to STAT 311 Programming Assignment 0

Welcome to STAT 311! This assignment is designed to refresh your R programming skills. You'll work with vectors, strings, data frames, and functions. Think of it like building a character in a video game: each part is a skill you need to level up. Let's dive in.

Part 1: Creating a Vector

In R, a vector is a sequence of elements of the same type. For this assignment, you need to create a vector called myVector with values [1, 2, 3, 4, 7]. Use the c() function:

myVector <- c(1, 2, 3, 4, 7)

This is similar to setting up a high-score list in a game: each value is a score.

Part 2: Storing Your Name in a String

Create a string variable myString that holds your name. In R, strings are enclosed in quotes:

myString <- "Your Name"

Replace "Your Name" with your actual name. This is like setting your player name in an online game.

Part 3: Finding the Hidden Value

Read the post on EdStem titled "Rule #1- Resolving Gradescope Submission Issues" to find the hidden value for HWO. Save it in a variable called HWOP3. For example:

HWOP3 <- "hidden_value_here"

This step teaches you to follow instructions carefully, a key skill in data science projects.

Part 4: Fixing Provided Code

The skeleton code may have errors. Common issues include missing parentheses, wrong data types, or incorrect function names. For instance, if you see read.csv('data.csv') but the file is named SampleData.csv, fix the filename. Do not change variable names or values. This is like debugging a mod in a game: you need to find and fix the glitch without breaking the game.

Part 5: Creating a Function

Write a function called myFunction that takes a 3x3 matrix or data frame and returns a vector of row sums. Here's an example:

myFunction <- function(data) {
  return(rowSums(data))
}

Test it on sampleData1 (the dataset from SampleData.csv). This is like calculating total points for each player in a leaderboard.

Tips for Success

  • Always set your working directory using setwd() in the console, not in the script.
  • Read data files by name only (e.g., read.csv("SampleData.csv")).
  • Check for syntax errors by running the entire script after clearing the environment.
  • Name your submission exactly STAT311-HWO.R.

By completing this assignment, you'll build a solid foundation for more complex statistical programming tasks. Good luck!