Hello!!!
I have a folder (C:/R/) with matrix files, named by number, i.e.
0.mat, 1.mat,...,1250.mat. In this case, they are 5x5 simetric
matrices. I would like to compute a property for each matrix and put
calculated values into a data frame for posterior ploting and
printing. Below there is an example for 7 matrices (0.mat..6.mat)
#define data frame
L <- data.frame(frame=numeric(7), L=numeric(7))
f0<-1/(5*(5-1)) # first variable for computation
#loop over matrices, Open it , calculate property and put into data frame
for(i in 0:6){
m<-matrix(scan('C:/R/i.mat', n=5*5),5,5, byrow=TRUE) # load matrix
f1<-geodist(m)
f2<-sum(colSums(f1$gdist))
l <-f0*f2
# Calculate property
L[i+1, ]<-c(i,l)
# Fill data frame
}
but the matrix cannot be loaded, because it try to open a file named
"i.mat". I don`t know how to loop with a counter named 'i',
and use it
to define the name of the file too. How can i do it? I have not found
the way.
Leonardo
use paste() to construct the file name e.g. fn <- paste(i,".mat",sep="") Sean On 12/08/05, Leonardo Sepulveda Dur??n <leonardosepulveda at gmail.com> wrote:> Hello!!! > > I have a folder (C:/R/) with matrix files, named by number, i.e. > 0.mat, 1.mat,...,1250.mat. In this case, they are 5x5 simetric > matrices. I would like to compute a property for each matrix and put > calculated values into a data frame for posterior ploting and > printing. Below there is an example for 7 matrices (0.mat..6.mat) > > #define data frame > L <- data.frame(frame=numeric(7), L=numeric(7)) > f0<-1/(5*(5-1)) # first variable for computation > > #loop over matrices, Open it , calculate property and put into data frame > for(i in 0:6){ > m<-matrix(scan('C:/R/i.mat', n=5*5),5,5, byrow=TRUE) # load matrix > f1<-geodist(m) > f2<-sum(colSums(f1$gdist)) > l <-f0*f2 > # Calculate property > L[i+1, ]<-c(i,l) > # Fill data frame > } > > but the matrix cannot be loaded, because it try to open a file named > "i.mat". I don`t know how to loop with a counter named 'i', and use it > to define the name of the file too. How can i do it? I have not found > the way. > > Leonardo > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
look at ?paste(), e.g.,
paste("C:/R/", i, "mat", sep = "")
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Leonardo Sepulveda Dur??n" <leonardosepulveda at
gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, August 12, 2005 4:44 PM
Subject: [R] evaluating string variables
> Hello!!!
>
> I have a folder (C:/R/) with matrix files, named by number, i.e.
> 0.mat, 1.mat,...,1250.mat. In this case, they are 5x5 simetric
> matrices. I would like to compute a property for each matrix and put
> calculated values into a data frame for posterior ploting and
> printing. Below there is an example for 7 matrices (0.mat..6.mat)
>
> #define data frame
> L <- data.frame(frame=numeric(7), L=numeric(7))
> f0<-1/(5*(5-1)) # first variable for computation
>
> #loop over matrices, Open it , calculate property and put into data
> frame
> for(i in 0:6){
> m<-matrix(scan('C:/R/i.mat', n=5*5),5,5, byrow=TRUE) # load
matrix
> f1<-geodist(m)
> f2<-sum(colSums(f1$gdist))
> l <-f0*f2
> # Calculate property
> L[i+1, ]<-c(i,l)
> # Fill data frame
> }
>
> but the matrix cannot be loaded, because it try to open a file named
> "i.mat". I don`t know how to loop with a counter named
'i', and use
> it
> to define the name of the file too. How can i do it? I have not
> found
> the way.
>
> Leonardo
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
Thanks a lot!!!
using
m<-matrix(scan(paste("C:/R/",i,".mat",sep=""),
n=5*5),5,5, byrow=TRUE)
worked very well!!!
Leonardo
Le 12.08.2005 16:44, Leonardo Sepulveda Dur??n a ??crit :>Hello!!! > >I have a folder (C:/R/) with matrix files, named by number, i.e. >0.mat, 1.mat,...,1250.mat. In this case, they are 5x5 simetric >matrices. I would like to compute a property for each matrix and put >calculated values into a data frame for posterior ploting and >printing. Below there is an example for 7 matrices (0.mat..6.mat) > >#define data frame >L <- data.frame(frame=numeric(7), L=numeric(7)) >f0<-1/(5*(5-1)) # first variable for computation > >#loop over matrices, Open it , calculate property and put into data frame >for(i in 0:6){ > m<-matrix(scan('C:/R/i.mat', n=5*5),5,5, byrow=TRUE) # load matrix > f1<-geodist(m) > f2<-sum(colSums(f1$gdist)) > l <-f0*f2 > # Calculate property > L[i+1, ]<-c(i,l) > # Fill data frame >} > >but the matrix cannot be loaded, because it try to open a file named >"i.mat". I don`t know how to loop with a counter named 'i', and use it >to define the name of the file too. How can i do it? I have not found >the way. > >Leonardo > >Here are two ways : paste('C:/R/',i,'.mat',sep="") sprintf("C:/R/%d.mat",i) Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ ~~~~~~ Romain FRANCOIS - http://addictedtor.free.fr ~~~~~~ ~~~~ Etudiant ISUP - CS3 - Industrie et Services ~~~~ ~~ http://www.isup.cicrp.jussieu.fr/ ~~ ~~~~ Stagiaire INRIA Futurs - Equipe SELECT ~~~~ ~~~~~~ http://www.inria.fr/recherche/equipes/select.fr.html ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
Given my own language inadequacies (I speak only one), I must, of necessity, refrain from criticizing the multilingual. However, in this one instance my sensibilities have been overwhelmed: "symmetric" , please :-) . Incidentally, you may find that file.path() is also useful. Cheers, Bert -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Leonardo Sepulveda Dur??n > Sent: Friday, August 12, 2005 7:44 AM > To: r-help at stat.math.ethz.ch > Subject: [R] evaluating string variables > > Hello!!! > > I have a folder (C:/R/) with matrix files, named by number, i.e. > 0.mat, 1.mat,...,1250.mat. In this case, they are 5x5 simetric > matrices. I would like to compute a property for each matrix and put > calculated values into a data frame for posterior ploting and > printing. Below there is an example for 7 matrices (0.mat..6.mat) > > #define data frame > L <- data.frame(frame=numeric(7), L=numeric(7)) > f0<-1/(5*(5-1)) # first variable for computation > > #loop over matrices, Open it , calculate property and put > into data frame > for(i in 0:6){ > m<-matrix(scan('C:/R/i.mat', n=5*5),5,5, byrow=TRUE) # > load matrix > f1<-geodist(m) > > f2<-sum(colSums(f1$gdist)) > > l <-f0*f2 > > # Calculate property > L[i+1, ]<-c(i,l) > > # Fill data frame > } > > but the matrix cannot be loaded, because it try to open a file named > "i.mat". I don`t know how to loop with a counter named 'i', and use it > to define the name of the file too. How can i do it? I have not found > the way. > > Leonardo > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Mac OS 10.3.9 R framework v. 2.1.1
I am attempting to put a fitted curve into each panel of a lattice
graph, but am failing to do so. I have tried writing a very
sophisticated function to do so. The function seems to work when used
with plot(), but does not do so inside a panel function in xyplot().
Any pointers would be appreciated.
#The example data
fact <- gl(2,7)
x <- rep(1:7,2)
y <- c(1,1,2,3,2,3,4,1,2,1,2,3,3,4)
plot(jitter(y/6) ~ x)
# The following user defined function puts a curve (I believe the
correct one) into the scatterplot
panel.predglm <- function(x, y) {
model.trial <- glm(cbind(y,6-y) ~ poly(x,2),
family=quasibinomial(link="logit"))
xfit <- seq(1,7, length=21)
yfit <- predict(model.trial, newdata=data.frame(x=xfit),
type="response")
lines(xfit,yfit) }
panel.predglm(x, y)
# My attempt to use it in a lattice xyplot, however, fails. It draws a
curve which in most cases is outside the dimensions of the plot. I
suspect that the prediction is on the scale of the link functions.
library(lattice)
xyplot(y/6 ~ x|fact, ylim=c(0,.8),
panel=function(x, y,...) {
panel.xyplot(jitter(x),jitter(y))
panel.predglm(x,y) }
)
Any thoughts?
Hank Stevens
Dr. Martin Henry H. Stevens, Assistant Professor
338 Pearson Hall
Botany Department
Miami University
Oxford, OH 45056
Office: (513) 529-4206
Lab: (513) 529-4262
FAX: (513) 529-4243
http://www.cas.muohio.edu/botany/bot/henry.html
http://www.muohio.edu/ecology/
http://www.muohio.edu/botany/
"E Pluribus Unum"