[R] How to find all single minima, i.e. only each one within each next part of analyzed vector (table)

Wu Gong ghowoo at gmail.com
Sat May 22 18:54:23 CEST 2010


I hope this will help.

### Find rows with minimum value from every 5 rows
## Create the data
mlb <- data.frame(mass_position=c(1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20),
	mass_value=c(9,2,3,2,5,6,7,8,9,10,2.1,12, 1,14,15,16,17,18,19,20),

mass_label=c("lab1","lab2","lab3","lab4","lab5","lab6","lab7","lab8","lab9","lab10",

"lab11","lab12","lab13","lab14","lab15","lab16","lab17","lab18","lab19","lab20")
)

## Sort the data three times
## Create result by selecting first rows of every 5 rows 
mlb2 <- mlb[order(mlb[,1] %/% 5.1, mlb[,2], mlb[,1]),][mlb[,1] %% 5 == 1,]

## Exclude rows which mass_value > 2
(mlb3 <- mlb2[mlb2[,2] <= 2,])

-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-find-all-single-minima-i-e-only-each-one-within-each-next-part-of-analyzed-vector-table-tp2227224p2227292.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list