How to use R for high school research data analysis
Princeton Journal of Pre-Collegiate Research

Learning how to use R for high school research data analysis can transform a good research project into a genuinely publishable one. R is free, powerful, and used by professional researchers at universities worldwide, which means you are not learning a workaround tool. You are learning the real thing.
This guide walks you through R from installation to interpretation. No prior programming experience is required. What is required is a willingness to be precise, patient, and methodical about your data.
Why R Belongs in Your High School Research Toolkit
Most students default to Excel or Google Sheets for data analysis. Those tools are fine for basic calculations, but they fall short when your research demands statistical rigor. R was built specifically for statistical computing, and it handles tasks that spreadsheets simply cannot, including regression modeling, hypothesis testing, and publication-quality data visualization.
Peer-reviewed journals, including those that publish pre-collegiate research, expect data to be analyzed with appropriate statistical methods. Submitting a paper with R-generated outputs signals to reviewers that you took your methodology seriously (and that your findings are reproducible). Reproducibility is a cornerstone of credible research. It means another researcher could run your exact code and get your exact results.
If you are planning to submit original work for publication, understanding how to analyze data rigorously is non-negotiable. Our guide on How To Analyze Data In A High School Research Project covers the broader analytical framework, and R fits directly into that framework as your primary instrument.
Setting Up R and RStudio
R is the programming language. RStudio is the interface that makes working with R far more manageable. You need both, and both are free.
Download R from cran.r-project.org and install it first.
Download RStudio Desktop from posit.co and install it second.
Open RStudio. You will see four panels: the console, the script editor, the environment, and the files or plots panel.
The console is where R executes commands immediately. The script editor is where you write and save your full analysis code. Always write your analysis in the script editor, not just the console. That way, your entire workflow is documented and reproducible from start to finish.
Installing Your First Packages
R's base installation covers a lot, but packages extend its capabilities significantly. For high school research data analysis, three packages will handle most of what you need.
tidyverse: A collection of packages for data manipulation and visualization, including ggplot2 and dplyr.
readr: Simplifies importing CSV files, which is how most survey and experimental data arrives.
psych: Provides descriptive statistics functions particularly useful for social science and psychology research.
Install them by typing the following into your console and pressing Enter:
install.packages(c("tidyverse", "readr", "psych"))
You only install packages once. After that, you load them at the start of each session using the library() function. For example: library(tidyverse).
How to Use R for High School Research Data Analysis: The Core Workflow
Every research data analysis in R follows the same basic sequence: import, inspect, clean, analyze, visualize, interpret. Master this sequence and you can apply it to any dataset in any discipline.
Step 1: Import Your Data
Save your data as a CSV file. Most survey platforms like Google Forms and Qualtrics export directly to CSV. Use the following command to import it into R:
data <- read_csv("your_file_name.csv")
Replace your_file_name.csv with your actual file name. The <- symbol assigns the imported data to an object called data. You can name this object anything meaningful to your project, such as survey_results or experiment_data.
Step 2: Inspect Your Data
Before analyzing anything, understand what you have. These three commands are your starting point:
head(data): Displays the first six rows so you can confirm the import worked correctly.
str(data): Shows the structure, including variable names and data types.
summary(data): Provides basic descriptive statistics for every variable, including minimum, maximum, mean, and median values.
Inspection is not optional. Skipping it is how errors enter your analysis undetected and undermine your conclusions.
Step 3: Clean Your Data
Real data is messy. Responses may be missing, variables may be mislabeled, and outliers may distort your results. The dplyr package (part of tidyverse) handles most cleaning tasks efficiently.
To remove rows with missing values: data <- na.omit(data)
To rename a column: data <- rename(data, new_name = old_name)
To filter out implausible values (for example, ages below 10 in a high school study): data <- filter(data, age >= 10)
Document every cleaning decision in your script with a comment (lines starting with # in R are comments and do not execute). Reviewers and journal editors may ask how you handled data irregularities. Your script is your answer.
Running Statistical Tests in R
The statistical test you choose depends on your research question and the type of data you collected. Here are the most commonly applicable tests for high school research projects.
Descriptive Statistics
Start every analysis with descriptive statistics. They summarize your data before you make any inferential claims. Use the describe() function from the psych package for a comprehensive output:
describe(data)
This returns mean, standard deviation, median, skewness, and kurtosis for every numeric variable. Include a descriptive statistics table in your paper's methods or results section. It gives readers the context they need to evaluate your findings.
Comparing Two Groups: The t-Test
If your research question asks whether two groups differ on a continuous variable (for example, whether students who sleep more than eight hours score higher on a focus assessment), use a t-test:
t.test(score ~ group, data = data)
R will return a t-statistic, degrees of freedom, p-value, and confidence interval. A p-value below 0.05 conventionally indicates a statistically significant difference between groups (though always interpret this in context, not in isolation).
Examining Relationships: Correlation and Regression
To measure the relationship between two continuous variables, use correlation:
cor(data$variable1, data$variable2)
For a more complete analysis that controls for other variables or predicts an outcome, use linear regression:
model <- lm(outcome ~ predictor1 + predictor2, data = data)
summary(model)
The summary output includes coefficients, standard errors, and an R-squared value indicating how much variance in your outcome your predictors explain. Regression is particularly powerful for social science, public health, and economics research at the pre-collegiate level.
Categorical Data: Chi-Square Test
When both your variables are categorical (for example, gender and preference for a policy option), use a chi-square test:
chisq.test(table(data$variable1, data$variable2))
This tests whether the distribution of one categorical variable differs across levels of another. It is a standard test for survey-based research in sociology, political science, and public health.
Visualizing Data with ggplot2
Visualization is not decoration. A well-constructed figure communicates what paragraphs of text cannot. The ggplot2 package produces publication-quality graphics with precise control over every element.
Creating a Bar Chart
For categorical data, a bar chart is often the clearest choice:
ggplot(data, aes(x = category_variable)) + geom_bar() + labs(title = "Your Title", x = "Category", y = "Count")
Creating a Scatter Plot
For examining relationships between two continuous variables:
ggplot(data, aes(x = variable1, y = variable2)) + geom_point() + geom_smooth(method = "lm") + labs(title = "Your Title")
The geom_smooth(method = "lm") layer adds a regression line, which visually reinforces your statistical findings. Every figure you include in a research paper should have a descriptive caption and should be referenced explicitly in your results section.
Connecting Your Analysis to a Publishable Paper
Running the analysis is only part of the work. The other part is translating your R output into clear, precise academic writing. Your results section should report statistical findings in standard format: the test statistic, degrees of freedom (where applicable), p-value, and effect size or confidence interval.
For example, a t-test result might read: Students in the experimental group scored significantly higher on the assessment (t(48) = 3.21, p = 0.002, 95% CI [1.4, 5.6]).
Your methods section should state which version of R you used and which packages your analysis depended on. This is standard practice in academic publishing and supports reproducibility.
If you are still developing your paper's structure, our Research Paper Outline Template High School Students provides a clear framework for organizing your work from introduction through conclusion. For examples of how published high school researchers present their findings, see our High School Research Paper Example Publishable resource.
Strong abstracts also require accurate statistical reporting. Review our Abstract Examples Published High School Research Papers to see how quantitative findings are summarized concisely at the top of a paper.
Common Mistakes to Avoid
Even students who learn R quickly can undermine their analysis through avoidable errors. These are the most consequential ones.
Choosing the wrong test for your data type. Running a t-test on categorical data produces meaningless output. Match your test to your variables before you run anything.
Ignoring assumptions. Most parametric tests assume normally distributed data. Use shapiro.test() to check normality before proceeding.
Over-interpreting p-values. A p-value below 0.05 does not prove your hypothesis. It means the result is unlikely under the null hypothesis. Interpret findings with appropriate caution.
Failing to document your code. An undocumented script is not reproducible. Comment every meaningful step.
Presenting figures without context. Every graph needs a title, labeled axes, and a caption. A figure that requires the reader to guess what it shows weakens your paper.
How to Use R for High School Research Data Analysis: Next Steps
Knowing how to use R for high school research data analysis puts you ahead of the vast majority of pre-collegiate researchers. It signals methodological seriousness to reviewers and strengthens the credibility of every claim you make in your paper.
The learning curve is real but manageable. Start with your actual dataset. Run descriptive statistics first. Add complexity incrementally. Each analysis you complete builds the fluency that makes the next one faster and more confident.
If your research is still in its early stages, our Research Proposal Example For High School Students can help you define your question and methodology before you collect data. A well-designed study produces data that is far easier to analyze, so the work you do upfront pays dividends at every stage that follows.
When your analysis is complete and your paper is taking shape, consider submitting to a peer-reviewed journal that evaluates student work on its merits (not on institutional affiliation or prestige). The Princeton Journal of Pre-Collegiate Research publishes original research across all disciplines through rigorous blind review. Every accepted paper receives a DOI, making your work permanently citable in the academic record. Explore our Blogs for more guidance on every stage of the research and publication process, and visit the Princeton Journal of Pre-Collegiate Research to learn about submission requirements and what our reviewers look for in a publishable manuscript.
Your research deserves to be taken seriously. R is one of the most powerful tools available to make that happen.
Read More

APA format for high school research papers: complete guide
By
RISE Research
Read more

MLA format for research papers: when and how
By
RISE Research
Read more

APA vs MLA vs Chicago: which to use for your paper
By
RISE Research
Read more

How to cite a dataset
By
RISE Research
Read more

In-text citations vs footnotes: how each works
By
RISE Research
Read more

What is a p-value, explained for high school researchers
By
RISE Research
Read more

What is regression analysis and when do you use it
By
RISE Research
Read more

What is standard deviation and why it matters
By
RISE Research
Read more

What is a t-test and when do you need one
By
RISE Research
Read more

What is effect size and why reviewers care
By
RISE Research
Read more

Common statistical mistakes in student papers
By
RISE Research
Read more

Research for biology majors: what to publish before applying
By
https://princeton-jpcr.org/
Read more

Research for economics majors
By
https://princeton-jpcr.org/
Read more

Research for political science majors
By
https://princeton-jpcr.org/
Read more

Research for English and humanities majors
By
https://princeton-jpcr.org/
Read more

Research for neuroscience majors
By
https://princeton-jpcr.org/
Read more

Undecided major: what research keeps your options open
By
https://princeton-jpcr.org/
Read more

Summer research timeline: June to August week by week
By
Princeton Journal of Pre-Collegiate Research
Read more

Research goals to set at the start of the school year
By
Princeton Journal of Pre-Collegiate Research
Read more

How to finish your research paper before finals season
By
Princeton Journal of Pre-Collegiate Research
Read more

New year research resolutions that actually stick
By
Princeton Journal of Pre-Collegiate Research
Read more
