I have a problem in R, which I can’t seem to solve.
I have the following dataframe:
I would like to:
- Find the unique combinations of the columns ‘Species’ and ‘Effects’
- Report the concentration belonging to this unique combination
- If this unique combination is present more than one time, calculate the mean concentration
And would like to get the following dataframe:
I have tried next script to get the unique combinations:
UniqueCombinations <- Data[!duplicated(Data[,1:2]),]
but don’t know how to proceed from there.
Thanks in advance for your answers!
Tina
Try the following (Thanks Brandon Bertelsen for nice comment):
Creating your data:
Using great package
plyrfor a bit of magic 🙂And this is a bit more complicated, but cleaner version (Thanks again to Brandon Bertelsen):