[R] Sequence generation in a table

Petr PIKAL petr.pikal at precheza.cz
Thu Dec 9 13:03:23 CET 2010


Hi

r-help-bounces at r-project.org napsal dne 09.12.2010 12:41:47:

> Dear Sir,
> 
> Sorry to bother you again. Sir, the R code provided by you gives me 
following output.
> 
> > yy <- lapply(c(257, 520, 110), seq, to=0, by=-100)
> > yy
> [[1]]
> [1] 257 157  57
> 
> [[2]]
> [1] 520 420 320 220 120  20
> 
> [[3]]
> [1] 110  10
> 
> The biggest constraint for me is here as an example I have taken only 
three 
> cases i.e. c(257, 520, 110), however in reality I will be dealing with 
no of 
> cases and that number is unknown. But your code will certainly generate 
me the
> required numbers. In above case for doing further calculations, I can 
define say 
> 
> yy1 = as.numeric(yy[[1]])
> yy2 = as.numeric(yy[2]])
> yy3 = as.numeric(yy[[3]])

Why? Those values are already numeric.

lapply(yy, is.numeric)

[[1]]
[1] TRUE

[[2]]
[1] TRUE

[[3]]
[1] TRUE

and you can use the same construction to perform almost any operation on 
list.

lapply(yy, max)
lapply(yy, mean)
lapply(yy, sd)
lapply(yy, t.test)

Regards
Petr


> 
> But when the number of cases are unknown, perhaps this is not the 
practical 
> way of me defining individually. So is there any way that I can have all 
the 
> sequence numbers generated can be accommodated in a single dataframe. I 
> sincerely apologize for disturbing you Sir and hope I am able to put up 
my 
> problem in a proper manner.
> 
> Regards
> 
> Vincy Pyne
> 
> 
> --- On Thu, 12/9/10, Jan van der Laan <rhelp at eoos.dds.nl> wrote:
> 
> From: Jan van der Laan <rhelp at eoos.dds.nl>
> Subject: Re: [R] Sequence generation in a table
> To: r-help at r-project.org, vincy_pyne at yahoo.ca
> Received: Thursday, December 9, 2010, 10:57 AM
> 
> Vincy,
> 
> I suppose the following does what you want. yy is now a list which 
allows for 
> differing lengths of the vectors.
> 
> > yy <- lapply(c(257, 520, 110), seq, to=0, by=-100)
> > yy[[1]]
> [1] 257 157  57
> > yy[[2]]
> [1] 520 420 320 220 120  20
> 
> 
> Regards,
> Jan
> 
> 
> On 9-12-2010 11:40, Vincy Pyne wrote:
> > c(257, 520, 110)
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list