Vectors and DataFrames. Character Vector: b <- c("one","two","three") numeric vector character vector Numeric Vector: a <- c(1,2,5.3,6,-2,4) Matrix: y<-matrix(1:20,

Slides:



Advertisements
Similar presentations
Introduction to R Brody Sandel. Topics Approaching your analysis Basic structure of R Basic programming Plotting Spatial data.
Advertisements

R for Macroecology Aarhus University, Spring 2011.
Outline Research Question: What determines height? Data Input Look at One Variable Compare Two Variables Children’s Height and Parents Height Children’s.
Objective: Dealing with data in C++ Agenda: Notes Essay Help.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Review Binary –Each digit place is a power of 2 –Any two state phenomenon can encode a binary number –The number of bits (digits) required directly relates.
Module 6 Matrices & Applications Chapter 26 Matrices and Applications I.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week2: Data Structure, Types and Manipulation in R.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Correlation and Covariance. Overview Continuous Categorical Histogram Scatter Boxplot Predictor Variable (X-Axis) Height Outcome, Dependent Variable (Y-Axis)
Correlation and Covariance
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Introduction to to R Emily Kalah Gade University of Washington Credit to Kristin Siebel for development of much of this PowerPoint.
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
Data Objects in R Vector1 dimensionAll elements have the same data types Data types: numeric, character logic, factor Matrix2 dimensions Array2 or more.
Using Client-Side Scripts to Enhance Web Applications 1.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
R-Studio and Revolution Analytics have built additional functionality on top of base R.
R Programming Yang, Yufei. Normal distribution.
Relational Operators Relational operators are used to compare two numeric values and create a boolean result. –The result is dependent upon the relationship.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
 A spreadsheet is a type of software which you can put and sort out data. It is also known as ‘Microsoft Excel’ What is a spreadsheet?
Chapter 16: Using Lookup Tables to Match Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Arrays and Strings. Why? Consider a class of 30 students, each has a score for hw1  Do we want to have 30 variables with different names?  Would it.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.

School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
Matlab Basic. MATLAB Product Family 2 3 Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit.
Table formats ArcGIS reads table in many formats: dBase format (shapefile) INFO format (workstation ArcInfo) Geodatabase table (MS Access in case of personal.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Data types S S T : S P R E A D S H E E T S SST 2 Spreadsheet 2 Data Types Name: ______________________ Class: ______________________.
Learn R Toolkit D Kelly O'DayExcel & R WorldsMod 2 - Excel & R Worlds: 1 Module 2 Moving Between Excel & R Worlds Do See & HearRead Learning PowerPoint.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
S-PLUS Lecture 4 Jaeyong Lee Pennsylvania State University.
R objects  All R entities exist as objects  They can all be operated on as data  We will cover:  Vectors  Factors  Lists  Data frames  Tables 
Array Accessing and Strings ENGR 1187 MATLAB 3. Today's Topics  Array Addressing (indexing)  Vector Addressing (indexing)  Matrix Addressing (indexing)
Querying Databases A query is a program that allows us to VIEW the data or operate on the data Several types of queries –Select query –Merge query –Summary.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,

1 PEER Session 02/04/15. 2  Multiple good data management software options exist – quantitative (e.g., SPSS), qualitative (e.g, atlas.ti), mixed (e.g.,
Data & Graphing vectors data frames importing data contingency tables barplots 18 September 2014 Sherubtse Training.
Actor Heights 1)Create Vectors of Actor Names, Heights, Date of Birth, Gender 2) Combine the 4 Vectors into a DataFrame.
Data Structures: Multi-Dimensional Arrays Damian Gordon.
Basics in R part 2. Variable types in R Common variable types: Numeric - numeric value: 3, 5.9, Logical - logical value: TRUE or FALSE (1 or 0)
Data Management Data Types R basic 11/11/2013. Data Types 1. Vector 2. Factor 3. Matrix 4. Array 5. List 6. Dataframe.
Working with R Marcin Krzystanek PhD student at Cancer Systems Biology group, CBS Technical University of Denmark.
Random Functions Selection Structure Comparison Operators Logical Operator
Chapter 9: Data types and data structures OCR Computing for A Level © Hodder Education 2009.
Review > unique(plates) > is.numeric(plates) > cut(ages, breaks=c(0,18,65,Inf), labels=c("Kid","Adult","Senior")) > letters > month.name > c(Inf, NA, NaN,
Working with data in R 2 Fish 552: Lecture 3. Recommended Reading An Introduction to R (R Development Core Team) –
Introduction to R user-friendly and absolutely free
Creates the file on disk and opens it for writing
Sections Text Mining Plan Twitter API twitteR package
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
Advanced Genomics - Bioinformatics Workshop
Uploading and handling databases
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
Numerical Descriptives in R
Creates the file on disk and opens it for writing
Vectors and DataFrames
MIS2502: Data Analytics Introduction to R and RStudio
C# Revision Cards Data types
Understanding Variables
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Starter Activities GCSE Python.
Presentation transcript:

Vectors and DataFrames

Character Vector: b <- c("one","two","three") numeric vector character vector Numeric Vector: a <- c(1,2,5.3,6,-2,4) Matrix: y<-matrix(1:20, nrow=5,ncol=4) Dataframe: d <- c(1,2,3,4) e <- c("red", "white", "red", NA) f <- c(TRUE,TRUE,TRUE,FALSE) mydata <- data.frame(d,e,f) names(mydata) <- c("ID","Color","Passed") List: w <- list(name="Fred", age=5.3) Data Structures Framework Source: Hadley Wickham

Numeric: e.g. heights String: e.g. names Dates: “ Factor: e.g. gender Boolean: TRUE, FALSE Variable Types

Actor Heights 1)Create Vectors of Actor Attributes Names, Heights, Date of Birth, Gender 2) Combine the 4 Vectors into a DataFrame

Create a variable (aka object) called ActorNames: Actors <- c("John", "Meryl", "Andre") Creating a Character / String Vector

Class, Length, Index class(Actors) length(Actors) Actors[2]

Create a variable called h (inches): h <- c(77, 66, 90) Creating a Numeric Vector / Variable Using just one letter for the name to make this quicker to enter.

Create a Character Vector DOB <- c(" ", " ", " " ) Use the as.Date() function: DOB <-as.Date(DOB) Each date has been entered as a text string (in quotations) in the appropriate format (yyyy-mm-dd). By enclosing these data in the as.Date() function, these strings are converted to date objects. Creating a Date Variable

Create a character vector: g <- c("m", "f", "m") class(g) Use the factor() function to convert to a categorical: g <- factor(g) Creating a Categorical / Factor Variable

Actors.DF <- data.frame(Name=Actor, Height=h, Birthday = DOB, Gender=g) Create a DataFrame from Vectors dim(Actors.DF) Actors.DF$Name

Rows and Columns

1234 Array of Rows and Columns Actors.DF[3,3] row 3, column 3 Actors.DF[1,] row 1 Actors.DF[2:3,] rows 2,3, all columns column 2 Actors.DF[,2] mean(Actors.DF[,2])

Add New Variable: Height -> Feet, Inches Actors.DF$F <- floor(Actor.DF$Height/12) Actors.DF$I <- Actor.DF$Height - (Actor.DF$ *12)

Sort Actors.DF[with(Actors.DF, order(-Height)), ]

> getwd() [1] "C:/Users/johnp_000/Documents" > setwd() getwd() setwd()

write.table(Actors.DF, "ActorData.txt", sep="\t", row.names = TRUE) write.csv(Actors.DF, "ActorData.csv") Write / Create a File