[R] Quickstart #2
Jim Lemon
bitwrit at ozemail.com.au
Sat Oct 7 16:04:54 CEST 2000
Hi Phil,
This might get you started.
Read the file, converting it to an array:
data.array<-as.array(read.table("datafile",...))
then 'apply' the function 'stepvar':
data.var<-t(apply(data.array,1,stepvar))
Here's the function:
stepvar<-function(vec){
veclen<-length(vec)
while(veclen > 1) {
vec[veclen]<-var(vec[1:veclen])
veclen<-veclen-1
}
vec[1]<-NA
return(vec)
}
'stepvar' replaces elements 2 to n of a vector with the variance of all
elements up to that element . (element 1 becomes NA).
You should then be able to plot successive rows of the original array
and the array of variances, perhaps even on the same plot, e.g.
plot(data.array[1,2:length(data.array[1,])])
points(data.var[1,2:length(data.var[1,])])
Hope this does what you want.
Jim
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list