[R] list to data.frame

Benjamin.STABLER@odot.state.or.us Benjamin.STABLER at odot.state.or.us
Thu Dec 19 19:25:03 CET 2002


R Help-

I have a list of 102 vectors all of the same type and length called
time.by.orig.  I can't data.frame(time.by.orig) but I can
data.frame(time.by.orig[1:length(time.by.orig)]).  Why is this?  Thanks for
your help. 

str(time.by.orig)
List of 102
 $ 1  : num [1:102]  1.34 17.39 14.36 14.22  7.56 ...
 $ 2  : num [1:102] 17.5  0.7 17.7 12.4 10.4 ...
 $ 3  : num [1:102] 14.063 17.568  0.754  8.065 15.100 ...
 $ 4  : num [1:102] 13.940 12.423  7.546  0.766 14.977 ...
 $ 100: num [1:102]  7.722 10.400 15.049 14.915  0.467 ...
 $ 101: num [1:102]  5.68 13.99 13.90 13.77  4.01 ...
 $ 102: num [1:102]  6.67 11.86 14.88 14.75  1.68 ...
 ......
 - attr(*, "dim")= int 102
 - attr(*, "dimnames")=List of 1
  ..$ : chr [1:102] "1" "2" "3" "4" ...


> data.frame(time.by.orig)
Error in as.data.frame.default(x[[i]], optional = TRUE) : 
        can't coerce array into a data.frame

> data.frame(time.by.orig[1:length(time.by.orig)])
 -Works fine


Benjamin Stabler
Transportation Planning Analysis Unit
Oregon Department of Transportation
Salem, OR 97301 USA

-----Original Message-----
From: Deepayan Sarkar [mailto:deepayan at stat.wisc.edu]
Sent: Thursday, December 19, 2002 9:42 AM
To: Nolwenn Le Meur; r-help at stat.math.ethz.ch
Subject: Re: [R] lattice and display


On Thursday 19 December 2002 08:33 am, Nolwenn Le Meur wrote:
> Hi,
>
> I have just started using lattice and it looks great. But I already have 3
> questions about xyplot display.
>
---------------------------------------------------------------------------
>- ---------------------------------
> 1.I would like to create two differeny xyplot with different color to
> identify my different groups but I have trouble applying colors.
> Here are the scripts
>
>  xyplot(resultdata$Y~resultdata$X ,
> data=resultdata,groups=resultdata$Block, panel="panel.xyplot",
>  panel.groups="panel.xyplot",
>  xlab="X",ylab="Y",pch="*",
>  col.groups=trellis.par.get("superpose.symbol")$col[1:6],cex=2,
>  key=list(space="right",
>  points=list(pch="*",
> 	     col=trellis.par.get("superpose.symbol")$col[1:6]),
>  text=list(paste("Block",1:6)))
>  )

This is supposed to be called like


xyplot(Y~X, data = resultdata, 
       groups = Block, 
       xlab="X", ylab="Y",
       pch="*",
       key=list(space="right",
                points=list(pch="*",
 	        col=trellis.par.get("superpose.symbol")$col[1:6]),
                text=list(paste("Block",1:6))))

There's no argument called col.groups, and the panel function you meant to
use 
was panel.superpose, not panel.xyplot (which you don't have to specify 
explicitly since it's the default).

> xyplot(resultdata$Y~resultdata$X |resultdata$Block, data=resultdata,
>  xlab="X",ylab="Y",
> col.groups=trellis.par.get("superpose.symbol")$col[1:6],cex=2,
>  key=list(space="right",
>  points=list(pch=trellis.par.get("superpose.symbol")$pch[1:6],
> 	     col=trellis.par.get("superpose.symbol")$col[1:6]),
>  text=list(paste("Block",1:6)))
>  )

What exactly are you trying to do here? You don't have a grouping factor, so

why is just 

xyplot(Y ~ X | Block, data = resultdata, 
       xlab="X", ylab="Y", cex = 2)

not OK ?


>
---------------------------------------------------------------------------
>- -------------------------------
>
> 2.For the latest formula I would also like to change the resultdata$Block
> label by the corresponding "Block x".

I'm not sure what you mean. If you are talking about the Labels in the strip

above each panel, that would come from the levels of the Block variable. So,

the Block variable has to be a factor, and it should have levels "Block 1" 
... "Block 6". See ?factor for how to do that.


>
---------------------------------------------------------------------------
>- -------------------------------
>
> 3.I finally would like to save my plot as "jpg" files under Linux but I
> loose the color.

How did you try to do this ?

Deepayan

______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list