Scoping Jan de Leeuw 102A_1 UCLA Department of Statistics Finding Objects 1 get () 2 mget() 3 getAnywhere() Jan de Leeuw 102A_1 UCLA Department of Statistics 1 > a <-function () x <-1 2 > a() 3 > x 4 Error: object "x" not found 5 > a <-function (x) x< <-1 6 > a() 7 > x 8 [1] 1 Jan de Leeuw 102A_1 UCLA Department of Statistics We will say more about the various types as we encounter them later on. For the time being, we mention that all objects "foo" have a length (foo) . For some objects, such as functions, length is always one. But objects with atomic mode (logical, integer, numeric, complex, character, and raw) are usually (but not always) vectors, and have a length equal to the number of elements. R does not have a scaler type, the number 1 is really an integer vector of length one and TRUE is a logical vector of length one. Jan de Leeuw 102A_1 UCLA Department of Statistics

We have mentioned typeof () . For any type "foo", we also have the functions is .foo () and as .foo () . is .foo (bar) returns TRUE if "bar" is a "foo", and FALSE otherwise. as .foo (bar) tries to convert "bar" to type "foo". It should be emphasized that R also has various derived structures such as vectors, factors, arrays, matrices, and data.frames, which are pieced together from components of various types. They usually also have an is .foo () and as .foo () . Jan de Leeuw 102A_1 UCLA Department of Statistics Next, objects have attributes. To see the attributes of object "foo", use attributes (foo) . To ﬁnd the value of attribute "bar" of "foo", use attr (foo, "bar" ) and to change it to "foobar", use attr (foo, "bar" ) <-foobar . Time for some code. Because we have not mentioned this explicitly yet, assigning a value "bar" to an object "foo" (which deﬁnes the object if it does not exist yet) is done in R by foo <-bar or (less commonly) by bar -> foo . Those who use foo = bar are misguided. Jan de Leeuw

This preview
has intentionally blurred sections.
Sign up to view the full version.