tutorial1 new
📚 tutorial1_new.pdf
Brief overview
This document introduces fundamental tools and techniques for data analysis using R and RStudio. It covers the initial setup, basic syntax, and practical methods for collecting and preparing data for analysis, laying the groundwork for subsequent statistical tasks.
Key points
- Installing and navigating R and RStudio environments.
- Understanding R's basic syntax and calculator functionality.
- Collecting and recording demographic and preference data.
- Creating and submitting data files in CSV format.
- The purpose and role of practice assignments in learning.
1. Introduction to R and RStudio
1.1 Installing and using R and RStudio
- R: A programming language and environment for statistical computing and graphics.
- RStudio: An integrated development environment (IDE) that makes using R easier.
- Installation: Download R and RStudio from their official websites if working on a personal computer.
- Alternative: For devices like Chromebooks, use RStudio via "Apps at Otago."
1.2 R syntax basics
- Arithmetic operators:
+: Addition-: Subtraction*: Multiplication/: Division^: Exponentiation (raising to a power)
- Case sensitivity: R distinguishes between uppercase and lowercase letters (e.g.,
LM()is different fromlm()). - Spaces: R ignores extra spaces in commands, so
x = 1is the same asx=1. - Command history: Use the up arrow key to cycle through previous commands.
- Command prompt:
>: Indicates R is ready for a new command.+: Appears when R expects you to finish a previous command, like closing parentheses.
1.3 R as a calculator
- Console panel: This is where you type commands and see results in RStudio.
- Performing calculations: Directly type arithmetic expressions into the console.
- Order of operations: R follows standard mathematical order of operations (PEMDAS/BODMAS).
Example:
3+4*5will be calculated as 3+(4×5)=23.
- Sequence generation: The colon operator
:creates a sequence of numbers.1:20generates numbers from 1 to 20.- Applying operations to sequences: Operations can be applied element-wise to sequences. For example,
(1:20)/2divides each number from 1 to 20 by 2.
1.4 Expressions versus assignments
-
Expression:
- A command that performs a calculation and displays the result.
- The result is not saved for later use.
- Example:
1+2+3+4+5+6+7+8+9+10
-
Assignment:
- A command that stores the result of a calculation in a variable (or "object").
- The result is not automatically displayed.
- To see the stored result, you must then type the variable name.
- Example:
summation = 1+2+3+4+5+6+7+8+9+10thensummationto display it.
Assignment passes a result to a variable; an expression shows a result.
1.5 Collecting group data
- Purpose: To gather basic demographic and preference data from a small group.
- Information to collect:
- Number of siblings (non-negative integer)
- Netflix usage (yes/no)
- Living on campus (on/off)
- Main travel mode (walk, cycle, bus, drive, other)
- Travel time from campus (in minutes)
- Attitude towards statistics (strongly dislike, dislike, neutral, like, strongly like)
- Exact keys: Use the precise wording provided for each answer (e.g., "yes", not "Yes" or "Y"). This ensures data consistency.
1.6 Creating a CSV file
- CSV file (Comma Separated Values): A simple text file format for storing tabular data.
- Spreadsheet software: Use programs like Excel to create the dataset.
- Column names: Use the exact names:
group_id,siblings,netflix,on_campus,travel_mode,travel_time,like_stat. - Each row: Represents one student's data.
- Saving the file:
- Save as
groupX.csv, whereXis your group number. - Ensure the file type is set to "CSV (Comma delimited)" to avoid common errors like
.csv.xlsx.
- Save as
A CSV file stores data with each value separated by a comma.
📝 Example:
group_id siblings netflix on_campus travel_mode travel_time like_stat 1 2 yes on walk 10 like 2 0 no off bus 25 neutral
1.7 Submitting the CSV file
- Nominate a representative from your group.
- Submit one copy of the
groupX.csvfile. - Submission platform: Follow instructions on Aoroa (e.g., Tutorials > Tutorial 1 > CSV Submission).
🔑 Important: Consistent data entry using exact keys is crucial for accurate analysis.
🔑 Important: CSV files are a standard way to import data into statistical software like R.
2. Creating and submitting a CSV file
2.1 Creating a CSV file
To create a CSV (Comma Separated Values) file, you will use spreadsheet software like Excel. This software organizes data into rows and columns, which can then be saved in a universally compatible format.
- Column headers: Define the categories of your data.
- Rows: Represent individual entries or records.
To create your group's CSV file:
- Open a spreadsheet program.
- Use the exact column names provided:
group_id,siblings,netflix,on_campus,travel_mode,travel_time,like_stat. - Each row in your file should represent one member of your group.
- You can download a synthetic file named
group0.csvfrom Aoroa and update it with your group's information.
📝 Example: For Netflix usage, use "yes" or "no". For living on campus, use "on" or "off".
After entering your data, save the file.
- Filename format:
groupX.csv, where X is your group number. - File type: Ensure you save it as a
.csv(Comma delimited) file, not the default.xlsxformat. Watch out for common errors likegroupX.csv.csv.
2.2 Submitting your CSV file
After completing your CSV file, one group member will submit it. This submission process is managed through the Aoroa learning platform.
- Nominate a representative: Your group should choose one person to submit the file.
- Submission location: Follow the path on Aoroa: Ihiraki∣Content→Tutorials→Tutorial1→CSVSubmission.
🔑 Important: This CSV submission is not graded. Tutorial marks are based on valid in-person attendance, requiring at least 40 minutes of active engagement.
2.3 Practice assignments
The document also introduces practice assignments as a study tool. These assignments are designed to help you prepare for graded assessments.
- Purpose: To provide valuable practice without affecting your final grade.
- Availability: Practice assignments will be available alongside assessed assignments, starting from Week 2.
🔑 Important: Always attempt the practice version of an assignment before tackling the assessed version.
🔑 Important: The entire topic focuses on practical data handling and submission, reinforcing the importance of precise formatting and following instructions for digital submissions.
© 2026 Maeve. All rights reserved. This content is protected by copyright.