[R] Help with subset
Peter Alspach
Peter.Alspach at plantandfood.co.nz
Thu Jan 21 20:35:32 CET 2010
Tena koe Jerry
I'm not sure exactly what you wish to do, but it would seem you could
create a character vector (myVars) containing all your merge field names
and then use a for() loop. Something like:
for (myV in myVars)
{
x116 <- subset(napt, Analysis_Soil %in% myV)
if (nrow(x116) > 8)
{
# steps for your analysis
}
}
HTH ......
Peter Alspach
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Jerry Floren
> Sent: Friday, 22 January 2010 5:04 a.m.
> To: r-help at r-project.org
> Subject: [R] Help with subset
>
>
> I am so happy about learning how to read in multiple Excel
> files, that I have to try and make another improvement. I
> know what I have been doing is clumsy, but it works.
> Hopefully, someone can suggest a more elegant solution. As a
> novice, I have been using MS-Word and mail merge to write my
> code. I start with about 2 pages of code, and end up with
> 2,220 merged pages that I copy and paste into R. You can
> probably guess that I am not a programmer.
>
> ## here is the start of my merge document. The "x116" line
> has the merge field, in this case "Bases-K Ammonium
> Acetate-2008-116". This changes for each soil sample, and for
> each type of analysis. ##
>
> napt <- read.table(file = "C:/Documents and
> Settings/jfloren/My
> Documents/R_Statistics/NAPT/NAPT_09/CertIn2010/Data_for_R/read
> in_all_for_2010_cert.csv
> ", header = TRUE, sep = ",")
> attach(napt)
>
> x116 <- subset(napt, Analysis_Soil %in% c("Bases-K Ammonium
> Acetate-2008-116"))
>
> detach(napt)
> attach(x116)
>
> #### End of merge document section for selecting the subset ###
>
> Once I get the subset isolated, I have no problems
> calculating the necessary statistics and can generate some
> wonderful graphs.
>
> I have two questions.
> 1. How do I select different subsets from a large table
> without resorting to using Word's Mail Merge?
> 2. I prefer to only analyze the results if at least nine labs
> submitted results for a particular test. How would I tell R
> to skip the analysis if the number of labs running a
> particular test is less than nine?
>
> Thanks,
>
> Jerry Floren
> Minnesota Department of Agriculture
>
>
> --
> View this message in context:
> http://n4.nabble.com/Help-with-subset-tp1049883p1049883.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list