How to properly use a generated test string as a name?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to properly use a generated test string as a name?

Mark Knecht
Title asks it all.

Thanks in advance,
Mark

a = 1:5
b1 = 2:6
Z = data.frame(a,b1)
Z

Z$b1

count = 1

MyName = paste("b",count,sep="")
MyName

Z$MyName

N = as.name(MyName)

Z$N

______________________________________________
[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.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: How to properly use a generated test string as a name?

Erik Iverson-3


Mark Knecht wrote:

> Title asks it all.
>
> Thanks in advance,
> Mark
>
> a = 1:5
> b1 = 2:6
> Z = data.frame(a,b1)
> Z
>
> Z$b1
>
> count = 1
>
> MyName = paste("b",count,sep="")
> MyName
>
> Z$MyName

Z[[MyName]]

______________________________________________
[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
|

Re: How to properly use a generated test string as a name?

David Winsemius

On Feb 9, 2011, at 2:20 PM, Erik Iverson wrote:

>
>
> Mark Knecht wrote:
>> Title asks it all.
>> Thanks in advance,
>> Mark
>> a = 1:5
>> b1 = 2:6
>> Z = data.frame(a,b1)
>> Z
>> Z$b1
>> count = 1
>> MyName = paste("b",count,sep="")
>> MyName
>> Z$MyName
>
> Z[[MyName]]


Also:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f

(And Iverson's solution is the "without any of this messing around"  
approach.)

David Winsemius, MD
West Hartford, CT

______________________________________________
[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
|

Re: How to properly use a generated test string as a name?

Mark Knecht
In reply to this post by Erik Iverson-3
On Wed, Feb 9, 2011 at 11:20 AM, Erik Iverson <[hidden email]> wrote:

>
>
> Mark Knecht wrote:
>>
>> Title asks it all.
>>
>> Thanks in advance,
>> Mark
>>
>> a = 1:5
>> b1 = 2:6
>> Z = data.frame(a,b1)
>> Z
>>
>> Z$b1
>>
>> count = 1
>>
>> MyName = paste("b",count,sep="")
>> MyName
>>
>> Z$MyName
>
> Z[[MyName]]
>

Thank you Erik. I don't think I would have found that for days.

Cheers,
Mark

______________________________________________
[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.
markknecht@gmail.com