{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_02_ho

lecture_02_ho - BIOS 735 Statistical Computing Michael Wu...

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

View Full Document Right Arrow Icon
BIOS 735: Statistical Computing Michael Wu Lecture 2: Scalars, Vectors, Arrays, Matrices and Lists August 25, 2011 Michael Wu (Lecture 2) BIOS 735 August 25, 2011 1 / 25
Background image of page 1

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

View Full Document Right Arrow Icon
R: What and why? Scripted language for statistical data manipulation and analysis. Follow up to S Awesomeness: I Free, public domain implementation. I Standard among professional statisticians in academia – becoming more and more popular in industry, too. I Better than many commercial products. I Multiple operating systems. I Beyond stats, it works like programming language allows automation and new function creation I Object oriented and functional programming structure I Data sets can be saved between sessions – don’t have to reload. I Open source: easy to get help and lots of new functions and resources. Annoyances: text based command submission. Michael Wu (Lecture 2) BIOS 735 August 25, 2011 2 / 25
Background image of page 2
Object Orientation/Functional Programming computer science concepts, but generally useful Example: Running linear regression SAS and SPSS produce tons of output vs. lm() produces an object containing everything (allowing you to pick and choose what you want) Polymorphism: generic functions can be applied to different types of objects Example 1: print a = "cow" b = 1 class(a); class(b) print(a); print(b) Example 2: plot a = c(1,4,-1,5,0, 8) x = rnorm(20) y = 2 * x+rnorm(1) plot(lm(y˜x)) Fewer commands since plot works on everything Michael Wu (Lecture 2) BIOS 735 August 25, 2011 3 / 25
Background image of page 3

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

View Full Document Right Arrow Icon
Functions (Example) Michael Wu (Lecture 2) BIOS 735 August 25, 2011 4 / 25
Background image of page 4
Scalars and Vectors No such thing as a Scalar in R. All objects are one-element vectors. Vectors are arrays of elements that all have the same “mode”: integers, numerics, characters, logicals, complex, object, etc. Example is.vector(1) foo = c(1,-1,12) is.vector(foo) bar = c("a", "duck", "fat") baz = c( 1+1i, 1-1i, 4+3i, 5+1i) class(foo); class(bar); class(baz) foobar = c(foo, bar); foobaz = c(foo, baz); barbaz = c(bar, baz) class(foobar); class(foobaz); class(barbaz) Michael Wu (Lecture 2) BIOS 735 August 25, 2011 5 / 25
Background image of page 5

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

View Full Document Right Arrow Icon
Vectors: Declaration and Generation Need to declare you intend variable to be a vector type: y[1] = 12 fails, but: y = vector(length=10) y[1] = 5 y[10] = 99 y[11] = 12 y = vector(length=10); y[1] = "cow" y[11] = "duck" y[12] = 99 length(y) Generating vectors: a = 1:10 b = -2:4 c = seq(10) d = seq(1,2, by = 0.1) e = seq(1,4, length = 22) f = seq(1, 9, by = pi) g = rep(42,10) h = rep(1:5, times = 3) i = rep(1:5, each = 3) j = 1:5 * 2 Michael Wu (Lecture 2) BIOS 735 August 25, 2011 6 / 25
Background image of page 6
Vectors: Arithmetic and Logical Operations Vector addition/multiplication (component-wise): x = c(1,2,3) y = c(12,14,9) x+y x * y Logical operations a = 5 a>0; a>5; a>=5; a<0; a ==0;
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 25

lecture_02_ho - BIOS 735 Statistical Computing Michael Wu...

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

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