Lecture 03 - 102A_3_oh

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

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

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

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

View Full Document
Objects What you create or load into R all becomes an R object. There are R objects of many diﬀerent 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
Objects What you create or load into R all becomes an R object. There are R objects of many diﬀerent 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 "ﬂoat" and "integer" both have storage mode "numeric". Lets ﬁrst look at a list of the important types (from the user’s point of view). Jan de Leeuw 102A_1 UCLA Department of Statistics

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

View Full Document
– 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
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

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
Assignments 1 <- 2 < <- 3 assign() 4 = Jan de Leeuw 102A_1 UCLA Department of Statistics
Scoping Jan de Leeuw 102A_1 UCLA Department of Statistics

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

View Full Document
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

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

View Full Document
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) .
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
Ask a homework question - tutors are online