library(dplyr) #load dplyrBIOL 204 Spring 2026 - Pre-Lab 5 Assignment
Introduction
This week, we will be carrying out the first stage of our algae bead experiments. In order to prepare to manipulate and analyze the data you collect in R, you will need to learn a few new functions in the dplyr package.
Remember to always load necessary packages into your library first!
The “Algae_Bead_Lab” project in Posit Cloud will be where you store and analyze all of the data you collect throughout the next two weeks. There is already a sample data file in this project (sampledata.csv) that contains data from three Chlorella bead samples with corresponding controls. The weight of the algae beads in each tube is also recorded. Your goal is to calculate normalized absorbance for each sample.
Step 1: Upload the sample_data.csv as a Data Frame
Make sure to name your data frame something appropriate for R. Keep it simple. Do not include spaces. (All code below uses the data frame name sample_data)
Step 2: Using the mutate() Function to Manipulate Data Frames
The mutate() function is a an important component of the dplyr package. This function allows you to create new columns in your data frame. These columns can be made from new data or also from manipulating current columns within the data frame.
Create a Column that Calculates the Difference between Sample and Mean Control Absorbance
Check the column names in your data frame before performing any calculations. You can either click on the data frame name or run the following code:
#read names of data frame
names(sample_data)[1] "species" "sample" "bead_wt" "abs" "ctrl_abs"
First let’s just create a new column to store mean control absorbance to see how mutate() works. The main argument in mutate is: mutate(new_column = …). Remember we always want to use a pipe with dplyr.
sample_data <- sample_data %>% #store mutated data in same data frame
mutate(mean_ctrl_abs = mean(ctrl_abs)) #add column for mean control absorance
#check to see if new column was created
sample_data species sample bead_wt abs ctrl_abs mean_ctrl_abs
1 chlorella 1 1.58 0.781 0.416 0.3936667
2 chlorella 2 1.43 0.659 0.336 0.3936667
3 chlorella 3 1.55 0.823 0.429 0.3936667
Step 3: Calculate Corrected and Normalized Absborbance
Now that you’ve seen how a column can be created with mutate() by manipulating other data stored in your data frame, you need to calculate normalized absorbance for each sample.
To account for background absorbance and differences in sample size, raw absorbance values are corrected and normalized in two steps.
First, absorbance is corrected relative to the mean control absorbance:
\[ A_{corrected} = \frac{A - \bar{A}_{ctrl}}{\bar{A}_{ctrl}} \]
where \(A\) is the sample absorbance and \(\bar{A}_{ctrl}\) is the mean control absorbance. This yields a unitless value reflecting the proportional difference from the control.
Second, \(A_{corrected}\) is standardized by bead weight to allow comparison across samples:
\[ \text{normalized absorbance} = \frac{A_{corrected}}{w_{bead}} \] where \(w_{bead}\) is the bead weight in grams. The resulting value represents control-corrected absorbance per gram of sample.
Your Task: Create Two New Columns to Store Corrected and Normalized Absorbance based on the Above Equations
If you completed the steps appropriately your new data frame will include two new columns for corrected and normalized absorbance similar to this: