[R] creating a variable using concatenation
David Winsemius
dwinsemius at comcast.net
Wed Mar 31 08:08:49 CEST 2010
On Mar 30, 2010, at 11:15 PM, Steve Chen wrote:
> You can try this:
>
> library(tutoR)
That's an interesting set of goals:
"Package to mask common functions so that inputs in error are
explained and able to be corrected, prior to execution. 'assist'
offers step-by-step assistance to correctly call a function such as
'par'. 'eg' picks out Examples first and foremost in help. With
'deskcheck', execution is initiated and the 'debug' flag utilized, to
help deskcheck a function.
> plot(eval.string(toplot))
Can't say as I learned very much about R by reading the code for
eval.string, but the idea of having a learning-mode for R that would
clue in the newbs among us when we committed common errors, rather
than wrapping things up in a GUI, has a certain intriguing aspect to
it. Is there a literature regarding how well such a strategy plays out
in practice?
--
David.
>
>
> Steve Chen
>
> On 2010/3/31 上午 09:24, zubin wrote:
>> A general problem i run into, i know there must be a simple solution.
>>
>> I like to create a variable by appending a 1 for example, (i need to
>> loop later on from 1 to X, thus the reason for this). So i assign
>> the
>> variable vplot with this value, however it has quotes and when i
>> use it
>> in a barplot, it throws an error. but the tcenter$X1 does exist,
>> its an
>> element of a data frame. So if i type directly it works, but i
>> like to
>> do this programmatically, as i have to generate a bunch of these
>> plots
>> and need to loop.
>>
>> So how do i concatenate to create a variable, then reference that
>> variable in a function call?
>>
>>
>> R> x<- data.frame(1,2,3,4,5,6,7,8)
>> R> x
>> X1 X2 X3 X4 X5 X6 X7 X8
>> 1 1 2 3 4 5 6 7 8
>> R> x$X1
>> [1] 1
>>
>> R> i=1
>> R> toplot<- paste("x$X",i,sep="")
>> R> toplot
>> [1] "x$X1"
>>
>> okay lets test:
>>
>> R> plot(x$X1)
>> -it works i see the plot
>>
>> however this DOES not work
>>
>> R> plot(toplot)
>>
>> Error in plot.window(...) : need finite 'ylim' values
>> In addition: Warning messages:
>> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by
>> coercion
>> 2: In min(x) : no non-missing arguments to min; returning Inf
>> 3: In max(x) : no non-missing arguments to max; returning -Inf
>>
>>
>> Thus, that's my problem, i know it must be simple - the variable
>> is equal to x$X1 but it does not work in a function call? i tried
>> many functions - always some type of error.
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list