[R] Sorting data from one column with strings

Eigenhuis, Annemarie A.Eigenhuis at uva.nl
Thu Nov 4 14:27:54 CET 2010

Try tapply().

For example:


For the Nitrogen column, the mean is calculated for each Species. (if the data frame below is in the object data)

Annemarie Eigenhuis 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ramsvatn Silje
Sent: donderdag 4 november 2010 13:28
To: R-help at r-project.org
Subject: [R] Sorting data from one column with strings


I have tried to find this out some other way, but unsuccessful I have to try this list.
I assume this should be quite simple.

I have a dataset with 4 columns, "Sample_no", "Species", "Nitrogen", "Carbon" in csv format. In the species column I have many different species with varying number of obs per species


"Sample_no"	"Species"	"Nitrogen"	"Carbon"
1		Cod		15.2		-19.0
2		Haddock	14.8		-20.2
3		Cod		15.6		-18.5
4		Cod		13.2		-20.1
5		Haddock	14.3		-18.8

And I want to calculate, mean, standard dev etc per species for the observations "Nitrogen" and "Carbon". And later do plots and stats with the different species. I will in the end have many species, so need it to be "automatic" I can't enter code for every species separate.

Can anyone help me with this? Or if this is the wrong list to sendt this question to, where do I send it?

Thank you very much in advance.

Best regards

Silje Ramsvatn

University of Tromsø

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list