[R] Subset by string name?
jim holtman
jholtman at gmail.com
Sat Nov 29 14:29:31 CET 2008
You need
Yut_are <- subset (Yut, Mark=="Arecaceae", select=c(X, Y, Mark))
for equality test (two "==")
On Sat, Nov 29, 2008 at 5:22 AM, Ophelia Wang
<opheliawang at mail.utexas.edu> wrote:
> Hi all,
>
> I thought this should be very simple, but I'm not sure where the
> problem is. I have a .txt data file that contains X and Y coordinates
> of trees and their family names:
>
> "X" "Y" "Mark"
> 0 28 "Sapotaceae"
> 1 30 "Meliaceae"
> 1 40 "Meliaceae"
> 1 60 "Mimosaceae"
> 1 76 "Olacaceae"
> 1.5 73 "Myristicaceae"
> 2 34 "Euphorbiaceae"
> 2 62 "Olacaceae"
> 2 86 "Mimosaceae"
> 2.5 36 "Arecaceae"
> 3 22 "Nyctaginaceae"
> 3 25 "Moraceae"
> 3 38 "Rubiaceae"
> 3 47 "Desconocido "
> 3 99 "Mimosaceae"
> 3.5 24 "Anacardiaceae"
> 3.5 57 "Sapotaceae"
> 4 1 "Lecythidaceae"
>
> Now I just want to work on one family for various spatial analyses in
> ads and spatstats, so I wrote:
>
> Yut <-read.delim(
> "C:/dissertation/data2006/Parcela_1-3/Yutsun_tree.txt", header = TRUE,
> sep = "\t", quote="\"", dec=".", fill = TRUE )
>
> Yut_are <- subset (Yut, Mark="Arecaceae", select=c(X, Y, Mark))
>
> However, the summary of Yut_are still contains trees of other families:
>
> X Y Mark
> Min. : 0.00 Min. : 0.00 Myristicaceae: 65
> 1st Qu.: 24.00 1st Qu.:24.00 Lecythidaceae: 60
> Median : 46.00 Median :51.00 Sapotaceae : 51
> Mean : 48.07 Mean :49.72 Moraceae : 45
> 3rd Qu.: 72.50 3rd Qu.:75.50 Arecaceae : 41
> Max. :100.00 Max. :99.00 Mimosaceae : 34
> (Other) :313
>
> Please tell me how do I subset a dataset like this to extract trees
> from only one or a few families? Thanks a lot!
>
> Ophelia
>
> --
> Yung-Ho (Ophelia) Wang
> Doctoral Candidate
> Department of Geography and the Environment
> University of Texas
> +1-512-232-1597
> opheliawang at mail.utexas.edu
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list