Hi,


On Wed, Mar 9, 2016 at 10:22 AM, Jan Kacaba <[email protected]> wrote:
> Hello I would like to assign a vector to list sequence. I'm trying my code
> bellow, but the output is not what inteded.
>
> # my code
> mls=vector(mode="list") # my list
> cseq=c(1:3) # my vector
> mls[cseq]=cseq
>
> I get following:
> [[1]]
> [1] 1
> [[1]]
> [2] 2
> [[1]]
> [2] 3
>
> What I need is this:
> [[1]]
> [1] 1 2 3
> [[1]]
> [2] 1 2 3
> [[1]]
> [2] 1 2 3


This doesn't make any sense as an R structure: you have three element
1 in your list.

Here's what I think you might want:
> cseq <- c(1:3) # my vector
> mls <- lapply(cseq, function(x)cseq)
> mls
[[1]]
[1] 1 2 3

[[2]]
[1] 1 2 3

[[3]]
[1] 1 2 3

Sarah

______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to