I have a data frame with three different columns: Wavelength, Sample, and Mean.
Wavelength <- c(400, 400, 400, 400, 400, 400)
Sample <- c("A.1", "A.2", "A.3", "AB.1", "AB.2", "AB.3")
Mean <- c(0.434, 0.347, 0.434, 0.674, 0.591, 0.857)
df <- data.frame(Wavelength, Sample, Mean)
df
Wavelength Sample Mean
1 400 A.1 0.434
2 400 A.2 0.347
3 400 A.3 0.434
4 400 AB.1 0.674
5 400 AB.2 0.591
6 400 AB.3 0.857
Is there a way to group by everything before the “.” in the sample column, and then put those rows into a separate data frame? An example of what I am looking for is like this:
>df
Wavelength Sample Mean
1 400 A.1 0.434
2 400 A.2 0.347
3 400 A.3 0.434
>df1
Wavelength Sample Mean
4 400 AB.1 0.674
5 400 AB.2 0.591
6 400 AB.3 0.857
I have more than 2 groups of samples, but these are just an example of what I am trying to do.