Hello,

Sam Albers wrote:
Hello there,

I have a situation where I would like to select the first row of a
particular factor for a data frame (data example below). So that is, I would
like to select the first entry when the factor1 =A and then the first row
when factor1=B etc. I have thousands of entries so I need some general way
of doing this. I have a minimal example that should illustrate what I am
trying to do. I am using R version 2.9.2, ESS version 5.4 and Ubuntu 9.04.

Thanks so much in advance!

Sam

#Minimal example

x <- rnorm(100)
y <- rnorm(100)
xy <- data.frame(x,y)
xy$factor1 <- c("A", "B","C","D")
xy$factor2 <- c("a","b")
xy <- xy[order(xy$factor1),]  #This simply orders the data to look more like
the actual data I am working with

Does

xy[!duplicated(xy$factor1),]

do what you want?

______________________________________________
R-help@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.

Reply via email to