[R] newbie: embeding seq in a list

Jessica Streicher j.streicher at micromata.de
Tue Oct 30 17:01:53 CET 2012


s <- seq(0.8, 1.2, by = 0.1)
as.list(s)

to get the first type of list from the sequence.

On 30.10.2012, at 16:51, ONKELINX, Thierry wrote:

> You first example is a list of 5 items, each item is a number
> The second example is a list with one item: a vector with 5 elements.
> 
> You'll need c() to make a vector of the item to get the same result.
> all.equal(list(c(0.8,0.9,1.0,1.1,1.2)), list(seq(0.8, 1.2, by = 1.1)))
> 
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
> + 32 2 525 02 51
> + 32 54 43 61 85
> Thierry.Onkelinx at inbo.be
> www.inbo.be
> 
> To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
> ~ Sir Ronald Aylmer Fisher
> 
> The plural of anecdote is not data.
> ~ Roger Brinner
> 
> The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
> 
> 
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens Anser Chen
> Verzonden: dinsdag 30 oktober 2012 13:42
> Aan: r-help at r-project.org
> Onderwerp: [R] newbie: embeding seq in a list
> 
> Suppose I want to create a structure containing the following values:
> 0.8,0.9,1.0,1.1,1.2
> 
> If I use
> 
> env <- list(0.8,0.9,1.0,1.1,1.2)
> 
> then R returns
> 
>> env
> [[1]]
> [1] 0.8
> 
> [[2]]
> [1] 0.9
> 
> [[3]]
> [1] 1
> 
> [[4]]
> [1] 1.1
> 
> [[5]]
> [1] 1.2
> 
> 
> But, if I try to 'save some key-strokes', and use
> 
> 
> env <- list(seq(0.8,1.2,by=0.1))
> 
> then R returns
> 
>> env
> [[1]]
> [1] 0.8 0.9 1.0 1.1 1.2
> 
> 
> I'd like the 'latter' to be equivalent to 'the former', but can't figure out how to achieve said aim.
> 
> Thanks in advance...
> 
>        [[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.
> * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
> Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
> The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.
> 
> ______________________________________________
> 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