S-PLUS Lecture 2 Jaeyong Lee Department of Statistics Pennsylvania State University.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

PL/SQL.
Statistical Software An introduction to Statistics Using R Instructed by Jinzhu Jia.
Introduction to C Programming
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
JavaScript, Fourth Edition
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Introduction to C Programming
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Piotr Wolski Introduction to R. Topics What is R? Sample session How to install R? Minimum you have to know to work in R Data objects in R and how to.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Ch13-1 Chap 13 Introduction to Matlab 13.1 Introduction MATLAB : The MATrix LABoratory program Not only is the MATLAB programming language exceptionally.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Introduction to Objective Caml. General comments ML is a purely functional language--there are (almost) no side effects There are two basic dialects of.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
1 Variables and Arithmetic Operators in JavaScript.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
S-PLUS Lecture 4 Jaeyong Lee Pennsylvania State University.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
The R Book Chapter 2: Essentials of the R Language Session 7.
Chapter 2: Basic Elements of C++
Chapter 6 JavaScript: Introduction to Scripting
Tokens in C Keywords Identifiers Constants
Documentation Need to have documentation in all programs
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Data Types, Identifiers, and Expressions
Naomi Altman Department of Statistics (Based on notes by J. Lee)
Variables and Arithmetic Operators in JavaScript
Naomi Altman Department of Statistics (Based on notes by J. Lee)
MATLAB DENC 2533 ECADD LAB 9.
IDENTIFIERS CSC 111.
Data Types, Identifiers, and Expressions
Introduction to C++ Programming
Basics of ‘C’.
T. Jumana Abu Shmais – AOU - Riyadh
“If you can’t write it down in English, you can’t code it.”
Chapter 2: Java Fundamentals
Lectures on Numerical Methods
Python Primer 1: Types and Operators
Chapter 2: Introduction to C++.
The Data Element.
The Data Element.
DATA TYPES AND OPERATIONS
Review of Java Fundamentals
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

S-PLUS Lecture 2 Jaeyong Lee Department of Statistics Pennsylvania State University

Naming Conventions Names in S-Plus are made up of upper- and lower-case alphabets, 0-9, and period, ‘.’, in any noninitial position. S is case sensitive. The underscore, ‘_’, is not available.

Language Layout S-Plus commands are either expressions or assignments. 1 – pi +exp(1.7) a <- 6 Commands are separated by either ‘;’ or a newline. a <- 7; b <- a*7 ‘#’ marks the rest of line as a comment. a + b # This is an illustration. If a command is not complete, S-Plus issues ‘+’ rather than ‘>’. ‘.Last.value’ stores the most recently evaluated non-assignment expression.

Language Layout-Continued If a command is not complete, S-Plus issues ‘+’ rather than ‘>’. a * exp(3 +.Last.value stores the most recently evaluated non- assignment expression. 1 – pi + exp(1.7).Last.value a <- 6.Last.value

Vectors In S-Plus, there are no scalars; vectors of length 1 are used instead. Vectors are made up of numeric, logical values, or character strings. But you can not mix them. Character strings can be entered with either double or single quotes, but will always be printed with double quotes.

Session: Vectors x <- c(1.2, 2.4, 2.7, 5.6, 7.2) colours <- c(“red”, “green”, “blue”, “white”) x[3] colours[2] x > 3 names(x) <- c(‘a’,’b’,’c’,’d’,’e’) x x[b] x[“b’] letters x[letters[1:3]] x[-(3:5)]

Vector Arithmetic Arithmetic operations on vectors are performed element by element. If two vectors in the same expression have different length, the expression will produce a vector with the same length as the longest in the expression. The shorter vectors are recycled until they match the length of the longest.

Session: Vector Arithmetic x <- 1:20 y <- 1:7 2*x sin(x) x+2y :1 seq(from=10, to = 1, by=.5) rep(x, times=3)

Logical Vectors Possible elements of a logical vector is T (True) and F (False). Logical operators are >, >=, <, <=, ==, !=. c1&c2 (intersection), c1|c2 (union), !c1 (negation). A logical vector can be used in ordinary arithmetic, in which case F and T become 0 and 1, respectively.

Session: Logical Vectors x <- 1:30 big 20 medium =10) & (x <=20) sum(x < 10)

Missing Value Marker, NA When an element of a vector is “not available” or “missing”, the special value NA can be used to reserve the place. In general, any operation on an NA becomes an NA.

Session: NA x <- 1:5 is.na(x) x[3] <- NA is.na(x)

Session: Character Vector X <- c(“abc”, “def”, “ghi”) paste(“abc”, “def) paste(“abc”, “def”, sep=“”) paste(c(“X”,”Y”),1:10,sep=“”)

Index Vectors Subsets of elements of a vector can by selected by appending to a name of the vector an index vector in square brackets. An index expression can appear on the receiving side of an assignment expression. There are four kinds of index vectors: a logical vector (in this case, the lengths of the vector and index vector must match.) a positive integral vector a negative integral vector a character string vector.

Intrinsic Attributes: mode and length Every object in S-Plus has two attributes, mode and length. The mode of a vector can be numeric, complex, logical, and character. The function attributes(x) gives all non-intrinsic attributes of x. There is a special attribute called class which was introduced to enhance object-oriented programming. For example, plot() will react a different class differently.

Session: Intrinsic Attributes x <- 1:10 mode(x) length(x) attributes(x) dim(x) <- c(2,5) attributes(x) dim(x) <- c(10) digits <- as.character(x) y <- as.numeric(digits) E <- numeric() E[4] <- 17

Session: Intrinsic Attributes x <- 1:10 mode(x) length(x) attributes(x) dim(x) <- c(2,5) attributes(x) dim(x) <- c(10) digits <- as.character(x) y <- as.numeric(digits) E <- numeric() E[4] <- 17 leukemia mode(leukemia) length(leukemia) attributes(leukemia) unclass(leukemia)