Quantcast

Substitute list value

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Substitute list value

Charles Stangor-2
I can't seem to determine how to get the name of a list member to
substitute:

ll <- list("a1" = "a","a2" = "b")

t1[t==ll[0], "v"] <- 99

why doesn't this substitute to:
t1[t=="a", "v"] <- 99

Thank you!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Substitute list value

Charles Stangor
I can't seem to determine how to get the name of a list member to
substitute:

ll <- list("a1" = "a","a2" = "b")

t1[t==ll[0], "v"] <- 99

why doesn't this substitute to:

t1[t=="a", "v"] <- 99

Thank you!




--
Charles Stangor
Professor

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Substitute list value

Charles Stangor
I can't seem to determine how to get the name of a list member to
substitute as a variable name:

ll <- list("a1" = "a","a2" = "b")

t1[t==ll[1], "v"] <- 99

why doesn't this substitute to:

t1[t=="a", "v"] <- 99

Thank you!




--
Charles Stangor
Professor



--
Charles Stangor
Professor

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Substitute list value

Michael Weylandt
It should. Reproducible example of it not?

Michael

On Jul 11, 2012, at 3:06 PM, Charles Stangor <[hidden email]> wrote:

> I can't seem to determine how to get the name of a list member to
> substitute as a variable name:
>
> ll <- list("a1" = "a","a2" = "b")
>
> t1[t==ll[1], "v"] <- 99
>
> why doesn't this substitute to:
>
> t1[t=="a", "v"] <- 99
>
> Thank you!
>
>
>
>
> --
> Charles Stangor
> Professor
>
>
>
> --
> Charles Stangor
> Professor
>
>    [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Substitute list value

Jessica Streicher
In reply to this post by Charles Stangor
two things:

- R always counts from 1, not from 0
- listmembers are accessed by using [[ ]] , not [ ]

try

t1[t==ll[[1]], "v"] <- 99

greetings Jessi


On 11.07.2012, at 15:47, Charles Stangor wrote:

> I can't seem to determine how to get the name of a list member to
> substitute:
>
> ll <- list("a1" = "a","a2" = "b")
>
> t1[t==ll[0], "v"] <- 99
>
> why doesn't this substitute to:
>
> t1[t=="a", "v"] <- 99
>
> Thank you!
>
>
>
>
> --
> Charles Stangor
> Professor
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Substitute list value

Charles Stangor-2
thanks!

On Fri, Jul 13, 2012 at 4:35 AM, Jessica Streicher <[hidden email]
> wrote:

> two things:
>
> - R always counts from 1, not from 0
> - listmembers are accessed by using [[ ]] , not [ ]
>
> try
>
> t1[t==ll[[1]], "v"] <- 99
>
> greetings Jessi
>
>
> On 11.07.2012, at 15:47, Charles Stangor wrote:
>
> > I can't seem to determine how to get the name of a list member to
> > substitute:
> >
> > ll <- list("a1" = "a","a2" = "b")
> >
> > t1[t==ll[0], "v"] <- 99
> >
> > why doesn't this substitute to:
> >
> > t1[t=="a", "v"] <- 99
> >
> > Thank you!
> >
> >
> >
> >
> > --
> > Charles Stangor
> > Professor
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
>


--
Charles Stangor
Professor and Associate Chair

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Substitute list value

Bert Gunter
In reply to this post by Jessica Streicher
Jessica:

On Fri, Jul 13, 2012 at 1:35 AM, Jessica Streicher <[hidden email]
> wrote:

> two things:
>
> - R always counts from 1, not from 0
> - listmembers are accessed by using [[ ]] , not [ ]
>

FALSE! -- or at least not clearly stated:

 > x <- list(a=letters[1:3],b=1:4)
> x[[2]]
[1] 1 2 3 4
> x[2]
$b
[1] 1 2 3 4

Note that the first is a vector, the second component of x; while the
second is a list whose only component is the second component of x.

-- Bert

>
> try
>
> t1[t==ll[[1]], "v"] <- 99
>
> greetings Jessi
>
>
> On 11.07.2012, at 15:47, Charles Stangor wrote:
>
> > I can't seem to determine how to get the name of a list member to
> > substitute:
> >
> > ll <- list("a1" = "a","a2" = "b")
> >
> > t1[t==ll[0], "v"] <- 99
> >
> > why doesn't this substitute to:
> >
> > t1[t=="a", "v"] <- 99
> >
> > Thank you!
> >
> >
> >
> >
> > --
> > Charles Stangor
> > Professor
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.
>



--

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Substitute list value

Duncan Murdoch-2
On 13/07/2012 9:50 AM, Bert Gunter wrote:

> Jessica:
>
> On Fri, Jul 13, 2012 at 1:35 AM, Jessica Streicher <[hidden email]
> > wrote:
>
> > two things:
> >
> > - R always counts from 1, not from 0
> > - listmembers are accessed by using [[ ]] , not [ ]
> >
>
> FALSE! -- or at least not clearly stated:
>
>   > x <- list(a=letters[1:3],b=1:4)
> > x[[2]]
> [1] 1 2 3 4
> > x[2]
> $b
> [1] 1 2 3 4
>
> Note that the first is a vector, the second component of x; while the
> second is a list whose only component is the second component of x.

I think Jessica was right, and clear.  List members are accessed using
[[ ]].  Lists are subsetted using [ ].  Your first example extracts the
second member of x.  Your second example constructs a new list with a
subset of the members that are in x.

Duncan Murdoch

>
> -- Bert
>
> >
> > try
> >
> > t1[t==ll[[1]], "v"] <- 99
> >
> > greetings Jessi
> >
> >
> > On 11.07.2012, at 15:47, Charles Stangor wrote:
> >
> > > I can't seem to determine how to get the name of a list member to
> > > substitute:
> > >
> > > ll <- list("a1" = "a","a2" = "b")
> > >
> > > t1[t==ll[0], "v"] <- 99
> > >
> > > why doesn't this substitute to:
> > >
> > > t1[t=="a", "v"] <- 99
> > >
> > > Thank you!
> > >
> > >
> > >
> > >
> > > --
> > > Charles Stangor
> > > Professor
> > >
> > >       [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] 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.
> >
> > ______________________________________________
> > [hidden email] 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.
> >
>
>
>

______________________________________________
[hidden email] 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.
Loading...