Lecture 03 - 102A_3_oh

Lecture 03 - 102A_3_oh - UCLA Department of Statistics...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
UCLA Department of Statistics Course 102A Introduction to Computational Statistics with R Part III: R Objects Jan de Leeuw Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 1

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

View Full DocumentRight Arrow Icon
Objects What you create or load into R all becomes an R object. There are R objects of many different types. All objects have a type and a storage mode which can be determined by typeof () and mode () . Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 2
Objects What you create or load into R all becomes an R object. There are R objects of many different types. All objects have a type and a storage mode which can be determined by typeof () and mode () . We will be mostly interested in types. Storage modes are mostly a grouping of types, for example types "float" and "integer" both have storage mode "numeric". Lets first look at a list of the important types (from the user’s point of view). Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 3

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

View Full DocumentRight Arrow Icon
– logical (TRUE and FALSE) – integer – double – complex – character – raw (bits) – list – NULL (the unique NULL object) – closure (a function) – environment – connection – namespace – symbol (name) Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 4
Characters R does not have single character object, in the same way as it does not have a scalar type for numbers. Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 5

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

View Full DocumentRight Arrow Icon
Characters R does not have single character object, in the same way as it does not have a scalar type for numbers. Objects of type character are vectors, with elements consisting of what is known elsewhere as strings. Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 6
1 > print (a <- c ( "aa" , "cc" , "ddd" , "1234" )) 2 [1] "aa" "cc" "ddd" "1234" 3 > a[4] 4 [1] "1234" 5 > as . character (1:5) 6 [1] "1" "2" "3" "4" "5" Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 7

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

View Full DocumentRight Arrow Icon
A string is a character vector of length one, such as "1234" . There are a number of string manipulation function, similar to the ones in C. See help . search ( "string" , package = "base" ) . There are functions for matching, concatenating, substringing, and uniquefying. We will not discuss them further, except the most important one 1 > paste ( "aa" , "bb" ) 2 [1] "aa bb" 3 > paste ( "aa" , "bb" ,sep= "" ) 4 [1] "aabb" Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 8
R has some useful built-in constants such as pi , but also the character vectors letters LETTERS month.abb month.name 1 > letters 2 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" " o" "p" "q" "r" "s" 3 [20] "t" "u" "v" "w" "x" "y" "z" Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 9

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

View Full DocumentRight Arrow Icon
Assignments 1 <- 2 < <- 3 assign() 4 = Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 10
Scoping Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 11

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

View Full DocumentRight Arrow Icon
Finding Objects 1 get () 2 mget() 3 getAnywhere() Jan de Leeuw 102A_1 UCLA Department of Statistics
Background image of page 12
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
Background image of page 13

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

View Full DocumentRight Arrow Icon
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) .
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2011 for the course STATS 102A 102A taught by Professor Jandeleeuw during the Fall '10 term at UCLA.

Page1 / 99

Lecture 03 - 102A_3_oh - UCLA Department of Statistics...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online