0

I have a data file with 7 fields. I am trying to aggregate the data based on one field (Individual) and summarize the data by another field (Diameter). My new data file gets rid of the other 5 fields from the original file. Is there a way to retain other fields when doing an aggregate function? See R code below.

Current R Code:

#add in data and verify 
SAG_v1 <- read_csv("C:/Users/jbryz/Downloads/SAG_v1.csv", show_col_types = FALSE)
head(SAG_v1)
#dissolve by field=individual to accounts for multi-stemmed measurements
library(dplyr)
SAG_sum <- SAG_v1 %>% 
  group_by(Individual) %>% 
  summarise(Diameter = sum(Diameter))
  • If you want to keep all non-aggregated data, use `mutate` instead of `summarise`. – r2evans Jan 20 '22 at 16:48
  • I suggest you either provide sufficient sample data from you `"SAG_v1.csv"`, or demonstrate your *intent* using `mtcars` or similarly small public dataset. Also, with this sample data, please show what you expect your output to be (i.e., how your current output is wrong). – r2evans Jan 20 '22 at 16:49
  • In addition to the good suggestions of @r2evans, example data may be provided by using `dput(SAG_v1)` or something similar. Please refer to [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more information. – Dion Groothof Jan 20 '22 at 17:02

0 Answers0