Programming in R Managing Variables. Managing variables in R In this session I will show you how to: Rename, drop and keep variables Create new variables.

Slides:



Advertisements
Similar presentations
Browse the codebook - to see the list of variables on which you can do statistics select the “Browse codebook in this window” option and then click “Start”
Advertisements

Internet Basics & Way Beyond!
Section 13-4: Matrix Multiplication
While opening master data will appear. Fill the name, Select the heads and click on next for going to computatin page Click here to go to Computation Click.
Intro to Excel - Session 5.31 Tutorial 5 - Session 5.3 Working with Excel Lists.
Maths for Computer Graphics
Here is a preview of one type of problem we are going to solve using matrices. Solve this system of equations:
Module 6 Matrices & Applications Chapter 26 Matrices and Applications I.
How to Use the R Programming Language for Statistical Analyses Part I: An Introduction to R Jennifer Urbano Blackford, Ph.D. Department of Psychiatry Kennedy.
Matrices The Basics Vocabulary and basic concepts.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Matrices Write and Augmented Matrix of a system of Linear Equations Write the system from the augmented matrix Solve Systems of Linear Equations using.
Chapter 2 Systems of Linear Equations and Matrices Section 2.4 Multiplication of Matrices.
Matrix Solution of Linear Systems The Gauss-Jordan Method Special Systems.
Little Linear Algebra Contents: Linear vector spaces Matrices Special Matrices Matrix & vector Norms.
1.1.2 INTRODUCTION TO SYSTEMS OF LINEAR EQUATIONS Chapter 1: Systems of Linear Equations and Matrices SWBAT: Redefine algebraic operations as Elementary.
Programming in R Getting data into R. Importing data into R In this session we will learn: Some basic R commands How to enter data directly into R How.
Review of Matrices Or A Fast Introduction.
Chapter 6 Matrices and Determinants Copyright © 2014, 2010, 2007 Pearson Education, Inc Matrix Solutions to Linear Systems.
Matrices NamingCalculatorApplication. Making & Naming a Matrix Matrix A.
Section 9.4 Systems of Linear Equations: Matrices
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
Class Opener:. Identifying Matrices Student Check:
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Matrix Algebra Section 7.2. Review of order of matrices 2 rows, 3 columns Order is determined by: (# of rows) x (# of columns)
8.2 Operations With Matrices
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
Systems of Linear Equations in Vector Form Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB.
Unit 3 Vocabulary Amelia N.. Algebraic Expression An expression that contains a variable. Examples: 10/p=2 p+11=20.
S-PLUS Lecture 4 Jaeyong Lee Pennsylvania State University.
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
R Workshop #2 Basic Data Analysis. What we did last week: Understand the basics of how R works Generated objects (vectors, matrices, etc.) Read in data.
Notes Over 4.4 Finding the Inverse of 2 x 2 Matrix.
Matrix Multiplication The Introduction. Look at the matrix sizes.
3.6 Multiplying Matrices Homework 3-17odd and odd.
= the matrix for T relative to the standard basis is a basis for R 2. B is the matrix for T relative to To find B, complete:
Notes Over 4.2 Finding the Product of Two Matrices Find the product. If it is not defined, state the reason. To multiply matrices, the number of columns.
Do Now: Perform the indicated operation. 1.). Algebra II Elements 11.1: Matrix Operations HW: HW: p.590 (16-36 even, 37, 44, 46)
4-3 Matrix Multiplication Objective: To multiply a matrix by a scalar multiple.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
Working with R Marcin Krzystanek PhD student at Cancer Systems Biology group, CBS Technical University of Denmark.
Matrices and systems of Equations. Definition of a Matrix * Rectangular array of real numbers m rows by n columns * Named using capital letters * First.
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
Mail Merge Introduction to Word Processing ITSW 1401 Instructor: Glenda H. Easter Introduction to Word Processing ITSW 1401 Instructor: Glenda H. Easter.
An Introduction to Matrix Algebra Math 2240 Appalachian State University Dr. Ginn.
Haas MFE SAS Workshop Lecture 3:
13.4 Product of Two Matrices
Lesson 43: Working with Matrices: Multiplication
12-1 Organizing Data Using Matrices
Linear Algebra review (optional)
Matrices - Addition and Subtraction
Linear Transformations
Solving Systems Using Matrices
DATA MANAGEMENT MODULE: Managing Variables
Introduction to Matrices
Introduction to SAS A SAS program is a list of SAS statements executed in order Every SAS statement ends with a semicolon! SAS statements can be in caps.
DATA MANAGEMENT MODULE: Managing Variables
Matrices Elements, Adding and Subtracting
CSCI N207 Data Analysis Using Spreadsheet
MATRICES MATRIX OPERATIONS.
Multidimensional array
Data Management Module: Creating, Adding and Dropping Variables
3.6 Multiply Matrices.
Linear Algebra review (optional)
Another take on the quadrant plots
Matrix A matrix is a rectangular arrangement of numbers in rows and columns Each number in a matrix is called an Element. The dimensions of a matrix are.
A drag and drop exercise can be created using Word quite easily using tables, text boxes and ensuring the document is saved properly.
Matrix Multiplication Sec. 4.2
Browse the codebook - to see the list of variables on which you can do statistics select the “Browse codebook in this window” option and then click “Start”
Presentation transcript:

Programming in R Managing Variables

Managing variables in R In this session I will show you how to: Rename, drop and keep variables Create new variables in a R dataset

Accessing Variables There are two basic ways to access variables. You can reference the column number or the variable number You can reference the variable name.

Accessing variables - indexing Data frames in R are special matrices. Matrices have the concept of rows and columns (rXc). To access a cell –X[r,c] To access a column –X[,c] To access a row –X[r,]

Access Variables For example, this will access all rows and column 1: fallsurvey[,1] This will access row 1 and all columns: fallsurvey[1,] This will access just the first obs in the first column: fallsurvey[1,1]

Managing Variables - Keep There are a few different ways to specify the variables to keep in the data set We can specify specific columns by the column number We can also keep columns by specifying the name

Managing Variables - Keep # Keep based on column number # fallsurvey1 <- fallsurvey[,1:2] head(fallsurvey1) str(fallsurvey1) # Keep based on variable name # fallsurvey2 <- fallsurvey[,c("Sem...Year","Adj.GPA","Section","Gen der..")] head(fallsurvey2)

Managing Variables - Drop # Drop based on column number # fallsurvey1 <- fallsurvey[,-2] head(fallsurvey1) fallsurvey2 <- fallsurvey[,names(fallsurvey)[c(-2,- 3)]] head(fallsurvey2)

Managing Variables - Drop At this time, we have not shown how to drop variables based on the variable name. There are many different ways to do this. We will show a method that uses matrix processing in the optional session.

Managing Variables - Renaming To rename a variable, you need to use the “names” function (we will discuss functions in more detail later). Basically, here you are calling the function, identifying the dataset, then identifying the vector (column) that you are renaming: names(fallsurvey)[names(fallsurvey)=="Sem...Year"] <- "Sem/Year" str(fallsurvey)

Managing Variables - Creating new variables Variables can be easily created from other variables available in the data set. Care must be taken to ensure the resulting variable appears in the expected location.

Managing Variables - Creating new variables total.drinks <- fallsurvey$Drinks.before.Noon+fallsurvey$Drinks.after.Noon head(total.drinks) ls() fallsurvey$total.drinks <- fallsurvey$Drinks.before.Noon+fallsurvey$Drinks.after.Noon head(fallsurvey$total.drinks) head(fallsurvey) Think about the difference between these two sets of code…