1. Home
  2. Explore
  3. Computer Science
  4. End-to-End Data Science

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

End-to-End Data Science

End-to-End Data Science with R

1. Data Science in Education

Data science in education is not only the use of statistical programming tools. Its larger purpose is to use data meaningfully to improve outcomes and opportunities for students.

A technical analysis has value when it:

  • Addresses a meaningful question.

  • Supports decisions that affect students, educators, or communities.

  • Can be understood and used by people who may not be data scientists.

  • Produces results that are practical rather than merely interesting to the analyst.

  • Fits within broader goals such as equity, accessibility, and effective planning.

Data science becomes meaningful when technical tools are used to solve problems that matter to others and to improve students’ lives.

Technical work and the “unspoken work” of data science

Writing code and solving data problems can be engaging as an individual activity. However, data science in education also requires work that may not appear in the code itself:

  • Identifying which problems deserve attention.

  • Learning what information communities and decision-makers actually need.

  • Explaining results to nontechnical audiences.

  • Connecting statistical findings to real-world decisions.

  • Considering how an analysis may promote or hinder equity.

  • Sharing the reasoning behind the analysis, not just the final result.

An analyst who solves only personally interesting problems may be pursuing a hobby at work rather than providing a useful service. The most valuable analyses connect technical skills with the needs of students, educators, and communities.


2. The R Data Science Ecosystem

The workflow described uses four connected tools:

  1. R

  2. RStudio

  3. R packages

  4. R Markdown

These tools are free or have free versions, and they work together to support data preparation, analysis, visualization, and reporting.


3. R: A Statistical Programming Language

R is a programming language designed especially for statistical analysis, data manipulation, and visualization.

R can be used to:

  • Prepare and clean data.

  • Calculate descriptive statistics.

  • Fit statistical models.

  • Create charts and other visualizations.

  • Generate reproducible reports.

  • Automate repeated analyses.

R was developed from the statistical programming language S by Ross Ihaka and Robert Gentleman at the University of Auckland. It was later released as open-source software, which is why R and much of its surrounding ecosystem can be used without licensing costs.

Why use a programming language for data analysis?

A programming language differs from a spreadsheet in several important ways:

  • The analysis is represented as explicit instructions.

  • The same steps can be repeated on new data.

  • The work can be checked and reproduced.

  • Complex operations can be automated.

  • The underlying process can be shared along with the result.

  • Large-scale analyses are easier to manage once the code has been written.

R is not the only language used for statistics. Python and other programming languages are also widely used. The important principle is to choose tools that fit the question and the scale of the work.


4. RStudio: The Working Environment

RStudio is an integrated development environment used to write and run R code. RStudio is not the R language itself.

R can be understood as the language that performs the statistical operations, while RStudio is the application that helps the analyst work with that language.

RStudio provides features such as:

  • An editor for writing code.

  • A console for running commands.

  • An environment pane showing data objects currently loaded.

  • File and project management.

  • Tools for viewing datasets.

  • Support for charts and other outputs.

  • Facilities for creating and rendering R Markdown documents.

R and RStudio analogy

The relationship between R and RStudio is similar to the relationship between a spoken language and a writing application:

  • R is like Spanish or another language used to express ideas.

  • RStudio is like Google Docs or Microsoft Word, which provides a workspace for writing and organizing those ideas.

  • The final analysis can then be shared as a PDF, webpage, GitHub project, or another format.

RStudio does not replace R. It provides an accessible environment for using R.


5. R Packages

An R package is a collection of additional functions, data, documentation, and sometimes example materials that extends R’s capabilities.

Packages can support tasks such as:

  • Data cleaning and preparation.

  • Statistical modeling.

  • Data visualization.

  • Report generation.

  • File management.

  • Specialized analyses.

Most packages are created and maintained by the R community. Analysts select packages based on the needs of their projects.

Packages used in the demonstration

tidyverse

The tidyverse is a collection of related R packages designed for data science. It provides tools for:

  • Importing data.

  • Filtering and transforming data.

  • Organizing datasets.

  • Summarizing information.

  • Creating visualizations.

The ggplot2 visualization package is part of the tidyverse.

here

The here package helps manage file paths and navigate a project’s file structure. It makes scripts easier to transfer between computers or share with other analysts because file locations can be handled more consistently.


6. R Markdown

R Markdown is a document format that combines written explanation, R code, and the results generated by that code.

R Markdown interweaves narrative with code and can dynamically generate results, tables, graphics, and reports.

An R Markdown document may contain:

  • Written descriptions of the research question.

  • Explanations of the methods.

  • R code chunks.

  • Tables created from the analysis.

  • Graphs and visualizations.

  • Interpretations and conclusions.

The document can be “knit,” or rendered, to produce a complete report.

Advantages of R Markdown

R Markdown resembles a word-processing document in several ways:

  • Text can be edited directly.

  • Narrative can be organized into sections.

  • Spelling and formatting tools are available.

  • The final document can be made readable for a general audience.

Its distinctive advantage is that code and results remain connected. This allows the report to be regenerated when the data or analysis changes.

R Markdown can produce outputs such as:

  • PDF documents.

  • Webpages.

  • HTML reports.

  • Files suitable for sharing through platforms such as GitHub.

R Markdown versus an R script

An R script is primarily a file containing R code. It is useful when:

  • The goal is to run analysis steps without extensive narrative.

  • A long or complicated data-preparation process should be kept separate.

  • Code needs to be reused in several reports.

  • A large number of programming lines would clutter a report.

An R Markdown document is useful when:

  • The analysis needs to combine code, explanation, tables, and graphics.

  • The results will be shared with other people.

  • The analyst wants the reasoning and output in one place.

  • A polished report is the desired product.

A common workflow is to explore data in an R script and later move the relevant analysis into R Markdown. Another approach is to work directly in R Markdown from the beginning. The best choice depends on the project and the analyst’s preferred workflow.

An R Markdown document can call or use code from a separate R script. This is useful when data preparation requires hundreds of lines of code or when the preparation process may need to be repaired or reused later.


7. The Data Analysis Workflow

A general data analysis workflow includes the following stages:

  1. Identify the question.

  2. Import the data.

  3. Prepare the data.

  4. Choose an analytical method.

  5. Visualize the data.

  6. Analyze and summarize the data.

  7. Interpret and communicate the results.

The workflow is not always perfectly linear. Data analysis is often exploratory. A result may lead to a new question, which may require revisiting an earlier preparation or analysis step.

Exploratory analysis as a conversation

Working in code can feel like a conversation with oneself:

  1. The analyst begins with a question.

  2. Code is written to investigate it.

  3. The result is examined.

  4. The result may suggest another question.

  5. The analyst modifies or extends the analysis.

  6. The process continues until the question is answered meaningfully.

This exploratory process encourages curiosity while preserving a record of the steps taken.


8. Example Analysis: Number of Schools per District

8.1 Planning question

The example considers a hypothetical county office planning a training service for all school districts in a county. Because resources are limited, the planners need to estimate how many schools each district has.

The analysis asks:

  • How many schools does each district have?

  • Are school counts similar across districts?

  • If counts differ, how large are the differences?

  • Could one average number be used to purchase materials in bulk?

  • Would a uniform allocation of materials work for every district?

The example focuses on school districts in San Diego County.


8.2 Importing a public dataset

The analysis uses publicly available enrollment data from the California Department of Education.

The dataset is imported with a function such as read_tsv(), which reads a tab-separated values file.

enroll <- read_tsv("file_name.tsv")

The imported dataset contains:

  • 131,616131{,}616131,616 rows.

  • 232323 columns.

  • Information from every county in California.

  • Information from schools throughout the state.

The dataset is stored in an object named enroll so that it can be referenced later.

Viewing the imported data

In R, data may not automatically appear in a spreadsheet-like view. The View() function can open the dataset in a table interface:

View(enroll)

This makes it easier to inspect the rows and columns.


8.3 Understanding the structure of the raw data

The raw dataset does not contain one row per school. Instead, each row represents a combination of characteristics such as:

  • County.

  • District.

  • School.

  • Ethnicity.

  • Gender.

Therefore, one school may appear multiple times. For example, a school may have separate rows for different demographic categories.

This structure is appropriate for some types of research, but it is not appropriate for directly counting schools. To answer the planning question, the data must first be reshaped conceptually so that each school appears once.

Data preparation depends on the question. A publicly available dataset is rarely ready-made for every possible analysis.


8.4 Filtering to San Diego County

The first preparation step is to keep only records from San Diego County.

The filter() function selects rows that meet a condition:

sd <- enroll %>%
  filter(county == "San Diego")

After filtering:

  • The dataset is reduced from 131,616131{,}616131,616 rows to approximately 10,87610{,}87610,876 rows.

  • All remaining records belong to San Diego County.

  • Multiple records for individual schools still remain.

Filtering reduces the data to the population relevant to the question.


8.5 Removing duplicate school records

The distinct() function keeps unique combinations of selected variables.

Because school names may be repeated in different districts, the analysis uses both district and school:

sd <- sd %>%
  distinct(district, school, .keep_all = TRUE)

This keeps one row for each unique district–school combination.

Why both district and school are needed

Using only the school name could incorrectly combine schools with identical names in different districts. For example, two districts might each contain a school with the same name.

The combination of:

  • District

  • School

provides a more reliable identifier for a unique school.

After removing duplicate demographic records:

  • The dataset contains approximately 795795795 unique schools.

  • Each school appears once.

  • The data is now ready for counting by district.


8.6 Counting schools by district

The count() function counts the number of rows associated with each value of a variable.

school_count <- sd %>%
  count(district, sort = TRUE)

Because each row now represents one school, counting the number of rows for each district gives the number of schools in that district.

Why the district variable is counted

The goal is to determine how many schools belong to each district. Therefore, the analysis counts occurrences of the district name.

For example:

  • If a district appears 555 times, it has 555 schools.

  • If a district appears 223223223 times, it has 223223223 schools.

The school name itself does not need to be counted because each school appears only once after the distinct() step.

Initial finding

The district counts show substantial variation:

  • San Diego Unified has approximately 223223223 schools.

  • Chula Vista is also large but has substantially fewer schools.

  • Other districts have much smaller numbers of schools.

This suggests that the districts are not similar in size. A single uniform estimate may therefore be misleading for planning purposes.


9. Choosing Summary Statistics

The planning question requires both a measure of typical district size and a measure of variation.

9.1 Mean

The mean, or average, is calculated by adding all district school counts and dividing by the number of districts.

In R, the mean() function calculates the average:

mean(school_count$n)

The result indicates the average number of schools per district.

9.2 Standard deviation

The standard deviation describes how much the values typically vary around the mean.

In R, the sd() function calculates the standard deviation:

sd(school_count$n)

A small standard deviation indicates that values are relatively close to the average. A large standard deviation indicates substantial variation.

Because the district school counts vary widely, the standard deviation is important. Reporting only the mean could create the false impression that most districts have approximately the average number of schools.

9.3 Summarizing the results

The summarise() function can calculate multiple summary statistics and return them in a compact result:

school_count %>%
  summarise(
    avg_schools = mean(n),
    standard_dev = sd(n)
  )

The example produces approximately:

  • Average: 161616 schools per district.

  • Standard deviation: 323232 schools.

These values show that the standard deviation is twice the mean, indicating very large variation among districts.


10. Visualizing the Data

10.1 Why visualization helps

Visualization allows the brain to compare quantities quickly, especially differences in length or height. A chart can make variation more apparent than a table of numbers.

A visualization can help answer questions such as:

  • Which districts are largest?

  • How different are the largest districts from one another?

  • Is the average representative of most districts?

  • Are there extreme values or outliers?

10.2 Limiting the chart to the largest districts

A chart containing all approximately 505050 districts may become difficult to read. The analysis therefore selects the largest districts for a simpler visualization.

The min_rank() function can rank values, and filtering can retain the highest-ranked districts:

top_10 <- school_count %>%
  filter(min_rank(desc(n)) <= 10)

Depending on ties or ranking behavior, the result may contain slightly fewer or more than exactly ten districts.

10.3 Creating a bar chart with ggplot2

ggplot2 creates visualizations by adding layers.

A basic plot begins with a dataset and aesthetic mappings:

ggplot(top_10, aes(x = district, y = n))

The geom_bar() function adds bars. With stat = "identity", the supplied values determine the bar heights:

ggplot(top_10, aes(x = district, y = n)) +
  geom_bar(stat = "identity")

Reordering categories

District names may initially appear in an unhelpful order. The reorder() function can sort districts according to their school counts:

ggplot(top_10, aes(x = reorder(district, n), y = n)) +
  geom_bar(stat = "identity")

Flipping the coordinates

Long district names can be difficult to read on a horizontal axis. coord_flip() changes the chart so that district names appear on the vertical axis:

ggplot(top_10, aes(x = reorder(district, n), y = n)) +
  geom_bar(stat = "identity") +
  coord_flip()

The resulting visualization makes the large difference between San Diego Unified and Chula Vista clear.

Visualization as an exploratory tool

The chart is not only for final presentation. It also helps the analyst understand the data while working:

  • It highlights unusually large districts.

  • It makes the distribution easier to interpret.

  • It helps test whether the mean is a useful summary.

  • It can reveal planning risks that a single statistic hides.


11. Interpreting and Communicating the Results

A basic report might state:

Districts in San Diego County have approximately 161616 schools on average.

However, this statement must be interpreted cautiously because the district sizes vary substantially.

11.1 Why the average alone is insufficient

If planning materials were purchased for exactly the average district size, the allocation would not work equally well for all districts:

  • Large districts would receive too few materials.

  • Small districts might receive more materials than needed.

  • Districts with substantially different sizes would require different allocations.

San Diego Unified has many more schools than Chula Vista, even though Chula Vista is itself one of the larger districts. A uniform allocation would risk leaving the largest district without adequate resources.

11.2 Explaining variation statistically

For a statistically knowledgeable audience, the difference between the largest district and the average can be expressed in terms of standard deviations.

The difference between San Diego Unified and the next-largest district is approximately seven standard deviations, indicating an exceptionally large difference relative to the overall variation. This reinforces the conclusion that a single uniform number would be inappropriate.

11.3 Practical implication

The analysis suggests that planning should account for district-specific size rather than assuming that every district is similar.

Possible planning responses include:

  • Allocating materials according to each district’s number of schools.

  • Creating several allocation tiers.

  • Treating very large districts separately.

  • Using district-level counts rather than a single countywide average.

  • Reassessing the counts over time as schools open, close, or change organizational structure.


12. Why Use Code Instead of a Calculator or Spreadsheet?

For a simple dataset, a calculator, spreadsheet, or pivot table may be faster. The appropriate tool depends on the task.

The example is intentionally simple so that the workflow can be understood. The primary benefit of code appears when the analysis must be repeated, expanded, or shared.

12.1 Code provides scale

A spreadsheet typically provides a finished product. Code provides both:

  1. The finished result.

  2. The recipe used to produce it.

The “recipe” can be applied to new data or modified for a related question.

Examples of scalable reuse

The same code could be adapted to:

  • Analyze ten years of data separately.

  • Examine whether the mean and standard deviation changed over time.

  • Repeat the analysis for the entire state.

  • Compare every county in California.

  • Generate a customized report for each county.

  • Replace one dataset with another while preserving the general workflow.

Performing these tasks manually in a spreadsheet would be much more difficult and more vulnerable to inconsistent steps.

12.2 Reproducibility

Code records exactly how the data was:

  • Imported.

  • Filtered.

  • Deduplicated.

  • Counted.

  • Summarized.

  • Visualized.

Another analyst can inspect the instructions, rerun them, identify errors, and adapt the analysis. This is especially important when reports must be updated regularly.

12.3 The initial investment and later payoff

Writing code may take longer than manually calculating a result, especially for someone who is learning. The payoff comes later through:

  • Reuse.

  • Automation.

  • Consistency.

  • Transparency.

  • Large-scale processing.

  • Easier updates.

  • Easier collaboration.


13. Starting a Data Science Project at Work

Learning a technical skill does not guarantee that the first analysis will be useful. Before beginning, an analyst should determine whether the question matters to the people who will use the results.

13.1 Start with the problem, not the tool

A strong process begins by asking:

  • What decision needs to be made?

  • Who will use the analysis?

  • What information would change the decision?

  • What problem does the analysis address?

  • How could the result benefit students?

  • What are the consequences of acting on the result?

  • What would happen if the analysis were incorrect or misunderstood?

Only after clarifying the purpose should the analyst decide whether R, a spreadsheet, a database query, or another tool is appropriate.

13.2 Share work with nontechnical audiences

Technical analyses should be translated into language that decision-makers can understand. Effective communication includes:

  • A clear statement of the question.

  • A concise explanation of the data.

  • A description of the method in accessible terms.

  • Visualizations that highlight important patterns.

  • A direct explanation of practical implications.

  • Appropriate cautions and limitations.

The code can be included for transparency, but the main report should not require the audience to understand programming.

13.3 Connect the analysis to service

The most valuable work uses technical skills in service of others. In education, that means connecting results to:

  • Student opportunity.

  • Equity.

  • Resource allocation.

  • Instructional improvement.

  • Special education services.

  • School and district planning.

  • Community needs.

An analysis should not be judged only by whether the code works. It should also be judged by whether the result helps people make better decisions.


14. Key Concepts and Functions

R ecosystem

  • R: Statistical programming language.

  • RStudio: Application for writing and managing R code.

  • R package: Extension that adds functions and capabilities to R.

  • R Markdown: Document combining narrative, code, analysis, and outputs.

  • Tidyverse: Collection of packages for data science workflows.

  • ggplot2: Visualization package included in the tidyverse.

  • here: Package that simplifies file-path management.

Data preparation

  • read_tsv(): Imports tab-separated data.

  • View(): Opens a dataset in a spreadsheet-like viewer.

  • filter(): Keeps rows that meet a condition.

  • distinct(): Keeps unique combinations of selected variables.

  • count(): Counts observations by a grouping variable.

Analysis and visualization

  • mean(): Calculates the arithmetic average.

  • sd(): Calculates standard deviation.

  • summarise(): Produces summary statistics.

  • min_rank(): Ranks values for filtering or comparison.

  • ggplot(): Begins a layered visualization.

  • geom_bar(): Adds bars to a chart.

  • reorder(): Reorders categories based on another variable.

  • coord_flip(): Switches the horizontal and vertical axes.


15. Overall Takeaways

The purpose of data science is not merely to produce code or statistics; it is to use evidence and technical tools to address meaningful problems.

  • A useful analysis begins with a clear and important question.

  • Data must be examined carefully to understand what each row represents.

  • Public datasets often require substantial preparation before analysis.

  • The dataset’s structure must match the question being asked.

  • Duplicate records must be handled appropriately before counting.

  • A mean should often be accompanied by a measure of variation such as standard deviation.

  • Visualizations help reveal differences that may be hidden in summary statistics.

  • A single average can be misleading when values vary widely.

  • Code is especially valuable when an analysis must be repeated, scaled, updated, or shared.

  • R Markdown connects the explanation, code, results, and graphics in one reproducible report.

  • Technical work should be communicated to nontechnical audiences.

  • The strongest educational data science work solves problems that matter to students, educators, and communities.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent