[R] [Q] Newbie (continued.. at least I got R running allready :-)

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue Jun 22 06:42:26 CEST 2004


"jeroen clarysse" <jeroen.clarysse at easynet.be> wrote:
	I'll restate the problem : i got a datafile with 2400 measuerements (every
	250msec) of a CO2 measurement device, capturing the breath of a subject. I
	uploaded such a sample here :
	
	http://www.psy.kuleuven.ac.be/leerpsy/data.csv
	
I stuffed that through an AWK script to convert
    hh:mm:ss:msc
to seconds and omit the INDEX field.  Plotting the
points, I noticed well-defined peaks, but they were flat-topped.

> x <- read.table("leer.dat", header=TRUE)

    This table has $t and $co2 columns.

> y <- rle(x$co2)
> n <- 2:(length(y$values)-1)
> b <- n[(y$values[n-1] < y$values[n]) & (y$values[n] > y$values[n+1])]
> i <- cumsum(y$lengths)[b]
> j <- i + 1 - y$lengths[b]
> plot(x, col="green")         # points in green
> points(x[j,], col="red")     # first point of each peak in red
> points(x[i,], col="black")   # last point of each peak in black

> g <- diff((x$t[i]+x$t[j])/2)

    This step first finds the mid-points of the peaks, and then
    finds the differences between them.

> g
 [1] 4.6125 3.3750 4.3875 3.4500 3.8625 3.6500 4.2750 3.9000 3.6750 4.8750
[11] 2.8375 2.9375 2.6875 2.3375 2.7375 2.4250

    There is quite a dramatic difference between the first ten inter-peak
    times and the last five.




More information about the R-help mailing list