[R] small problem in coding

MacQueen, Don macqueen1 at llnl.gov
Sat Nov 27 04:33:55 CET 2010


As Nick suggested, you're confusing the name of an object with the name(s)
of its elements.

Study this example:

> 
> lamda <- 0.2
> lamda
[1] 0.2

> lamda <- c(g=0.2)
> lamda
  g 
0.2 

> lamda <- c(1,3,4)
> lamda
[1] 1 3 4

> lamda <- c(g=1, x=3, foo=4)
> lamda
  g   x foo 
  1   3   4 


lamda is now a numeric object of length 3, that is, it has 3 elements.
Each of the elements has a name.

> names(lamda)
[1] "g"   "x"   "foo"


The name of the object itself is "lamda". The names of its elements are
"g", "x", and "foo". To get the value of the element named "x" do this:

> lamda['x']
x 
3 


lamda['x'] return the value of the element named "x", no matter what
position it is.

Compare:

> lamda[2]
x 
3 


Which returns the value of the second element, no matter what it is named.

An object named "g", and the element of lamda named "g" are completely
independent of each other:

> g <- 0.5
> 
> g
[1] 0.5
> lamda['g']
g 
1 


Hope this helps
-Don

-- 
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
925 423-1062




On 11/26/10 12:12 AM, "Mike Gibson" <megalops31 at hotmail.com> wrote:

>
>I must be missing something.
> 
>I first state my g parameter with:
> 
>> lamda<-c(g=0.2)
>
>However, when I do the next step R is telling me "object g not found"
>Here is my next step:
> 
>> Q<-exp(g)
> 
> 
>???  
> 
>Any help would be greatly appreciated.
> 
>Mike              
>    [[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.



More information about the R-help mailing list