Hi,
I have the following matrix (named m):
key
sensor_date Laser_1 Laser_2
Laser_3
2010-09-30T15:00:12+0200 6 3
1
2010-10-31T15:05:07+0100 5 4
2
2011-09-30T15:00:12+0200 6 3
1
2011-10-31T15:05:07+0100 5 4
2
I plot the first column with the following function:
plot(m[,1],type="o",
xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1,
max(m[,1:length(colnames(m))])+1))
for the other columns I use there functions:
lines(m[,2],type=\"o\")
lines(m[,3],type=\"o\")
ok, it works.
But is there a way to do this prodcedures recursively??
for example:
for each columns {
lines(m[,column],type=\"o\")
}
I try with :
lines(m[,2:length(colnames(m))],type=\"o\")
but it doesn't work.
Thanks .
Alberto
--
View this message in context:
http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3067283.html
Sent from the R help mailing list archive at Nabble.com.
Take a look at ?matplot HTH, Gerrit On Wed, 1 Dec 2010, alcesgabbo wrote:> > Hi, > > I have the following matrix (named m): > key > sensor_date Laser_1 Laser_2 > Laser_3 > 2010-09-30T15:00:12+0200 6 3 > 1 > 2010-10-31T15:05:07+0100 5 4 > 2 > 2011-09-30T15:00:12+0200 6 3 > 1 > 2011-10-31T15:05:07+0100 5 4 > 2 > > I plot the first column with the following function: > plot(m[,1],type="o", xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1, > max(m[,1:length(colnames(m))])+1)) > > for the other columns I use there functions: > > lines(m[,2],type=\"o\") > > lines(m[,3],type=\"o\") > > ok, it works. > > But is there a way to do this prodcedures recursively?? > > for example: > > for each columns { > lines(m[,column],type=\"o\") > } > > I try with : > > lines(m[,2:length(colnames(m))],type=\"o\") > > but it doesn't work. > > Thanks . > Alberto > -- > View this message in context: http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3067283.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >--------------------------------------------------------------------- AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner
On 12/01/2010 02:43 PM, alcesgabbo wrote:> > I plot the first column with the following function: > plot(m[,1],type="o", xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1, > max(m[,1:length(colnames(m))])+1)) > > for the other columns I use there functions: > > lines(m[,2],type=\"o\") > > lines(m[,3],type=\"o\") > > ok, it works. > > But is there a way to do this prodcedures recursively?? > > for example: > > for each columns { > lines(m[,column],type=\"o\") > } > > I try with : > > lines(m[,2:length(colnames(m))],type=\"o\")Is there a special need to do it recursively? Would the following not do the trick, too? m <- matrix(c(1,6,3,2,5,4,3,6,3,4,5,4), byrow=TRUE, ncol=3) matplot(m, type="o", xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1, max(m[,1:length(colnames(m))])+1), lty=1, col="black") Or simply: matplot(m, type="o", xaxt="n", lty=1, col="black") Hope this helps, Roland
thanks! very useful -- View this message in context: http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3067443.html Sent from the R help mailing list archive at Nabble.com.
for data.frame: for(j in grep('Laser_', names(m)) lines(m[,j])
for matrix: for(j in grep('Laser_', colnames(m)) lines(m[,j])
or
for(j in 2:4) lines(m[,j])
Shorter could be worse if you insert additional columns later.
--
View this message in context:
http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3106041.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]
for data.frame: for(j in grep('Laser_', names(m)) lines(m[,j])
for matrix: for(j in grep('Laser_', colnames(m)) lines(m[,j])
or: for(j in 2:4) lines(m[,j])
Shorter could be worse if you insert additional columns later.
alcesgabbo wrote:>
> Hi,
>
> I have the following matrix (named m):
> key
> sensor_date Laser_1 Laser_2
> Laser_3
> 2010-09-30T15:00:12+0200 6 3
> 1
> 2010-10-31T15:05:07+0100 5 4
> 2
> 2011-09-30T15:00:12+0200 6 3
> 1
> 2011-10-31T15:05:07+0100 5 4
> 2
>
> I plot the first column with the following function:
> plot(m[,1],type="o",
xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1,
> max(m[,1:length(colnames(m))])+1))
>
> for the other columns I use there functions:
>
> lines(m[,2],type=\"o\")
>
> lines(m[,3],type=\"o\")
>
> ok, it works.
>
> But is there a way to do this prodcedures recursively??
>
> for example:
>
> for each columns {
> lines(m[,column],type=\"o\")
> }
>
> I try with :
>
> lines(m[,2:length(colnames(m))],type=\"o\")
>
> but it doesn't work.
>
> Thanks .
> Alberto
>
--
View this message in context:
http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3106392.html
Sent from the R help mailing list archive at Nabble.com.