[R] Splitting Datasets

Jack Tanner ihok at hotmail.com
Mon Mar 28 05:28:54 CEST 2011


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



More information about the R-help mailing list