On R 2.12 for Mac OSX, I have a dataset with both numerical and character values. I want to split dataset "ZIDL", into individual datasets based on the string content of variable "Dept". I can create one subset dataset at a time using a script I found on the net, but rather than run the same function 17 times, can R look at the "Dept" variable and create subset datasheets of the main datasheet (one for each department) with a single command? In Minitab, this would be the "Split Worksheet" function. I am horrible at scripting, but trying to learn fast. Thanks in advance, Robert [[alternative HTML version deleted]]
Wainscott, Robert LT <robert.wainscott <at> cvn74.navy.mil> writes:> I want to split dataset "ZIDL", into individual datasets based on the > string content of variable "Dept".There are many, many ways to do this, depending on what you're really after. Here's one: depts = levels(factor(zidl$dept)) for (i in 1:length(depts)) { tiny.dataset = subset(zidl, dept==depts[i]) # now do whatever processing you need with tiny.dataset } Read the Introduction to R and the help page for the subset command, i.e., ?subset
Please start by read ing An Introduction to R. You need to understand R data structures and how it works AS A LANGUAGE. Forget about Minitab (while you are in R). ?tapply -- Bert On Sun, Mar 27, 2011 at 5:50 PM, Wainscott, Robert LT <robert.wainscott at cvn74.navy.mil> wrote:> On R 2.12 for Mac OSX, I have a dataset with both numerical and > character values. > > > > I want to split dataset "ZIDL", into individual datasets based on the > string content of variable "Dept". > > > > I can create one subset dataset at a time using a script I found on the > net, but rather than run the same function 17 times, can R look at the > "Dept" variable and create subset datasheets of the main datasheet (one > for each department) with a single command? > > > > In Minitab, this would be the "Split Worksheet" function. > > > > I am horrible at scripting, but trying to learn fast. > > > > Thanks in advance, > > > > Robert > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Hi, Answers inline: On Sun, Mar 27, 2011 at 8:50 PM, Wainscott, Robert LT <robert.wainscott at cvn74.navy.mil> wrote:> On R 2.12 for Mac OSX, I have a dataset with both numerical and > character values. > > I want to split dataset "ZIDL", into individual datasets based on the > string content of variable "Dept". > > I can create one subset dataset at a time using a script I found on the > net, but rather than run the same function 17 times, can R look at the > "Dept" variable and create subset datasheets of the main datasheet (one > for each department) with a single command? > > In Minitab, this would be the "Split Worksheet" function.There is a "split" function in R: R> ?split> I am horrible at scripting, but trying to learn fast.As Bert mentioned, you have to learn the basics of the language first, otherwise you'll never get past the "stabbing in the dark" feeling. You can start here: http://cran.r-project.org/doc/manuals/R-intro.html Take a couple of hours to go through that -- there's no way to "learn fast" without first starting slow. Good luck, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact