Data Management Data Types R basic 11/11/2013. Data Types 1. Vector 2. Factor 3. Matrix 4. Array 5. List 6. Dataframe.

Slides:



Advertisements
Similar presentations
Whats your favorite color? a pear a green pear.
Advertisements

Using R with Python.
Introduction to R Brody Sandel. Topics Approaching your analysis Basic structure of R Basic programming Plotting Spatial data.
R for Macroecology Aarhus University, Spring 2011.
R for Macroecology Functions and plotting. A few words on for  for( i in 1:10 )
Training on R For 3 rd and 4 th Year Honours Students, Dept. of Statistics, RU Empowered by Higher Education Quality Enhancement Project (HEQEP) Department.
CS1020 Week 13: 16 th April Contents  Sit-in Lab #4 2.
Statistical Software An introduction to Statistics Using R Instructed by Jinzhu Jia.
Basics of Using R Xiao He 1. AGENDA 1.What is R? 2.Basic operations 3.Different types of data objects 4.Importing data 5.Basic data manipulation 2.
Arrays  An array is a collection of like elements.  There are many engineering applications that use arrays.  MATLAB ® stores data in arrays and performs.
A) 80 b) 53 c) 13 d) x 2 = : 10 = 3, x 3 = 309.
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
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.
Information Technology Center Hany Abdelwahab Computer Specialist.
Introduction to Exploratory Descriptive Data Analysis in S-Plus Jagdish S. Gangolly State University of New York at Albany.
Programming with R and Bioconductor for microarray expression analysis and interpretation Ramsi Haddad
Introduction to R Data Structure June Introduction to R: Data structure Karim & Maria June
Introduction to R Data import/export; Basic operations 2007 R 統計軟體研習會 蔡政安 Associate Professor Department of Public Health & Biostatistics Center China.
732A44 Programming in R.  Self-studies of the course book  2 Lectures (1 in the beginning, 1 in the end)  Labs (computer). Compulsory submission of.
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Data Objects in R Vector1 dimensionAll elements have the same data types Data types: numeric, character logic, factor Matrix2 dimensions Array2 or more.
COMP 116: Introduction to Scientific Programming Lecture 28: Midterm #2 Review.
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.
ARGUMENT 'FUN' IS MISSING, WITH NO DEFAULT: AN R WORKSHOP.
R-Studio and Revolution Analytics have built additional functionality on top of base R.
Introduction to R and Statistics Thomas INGICCO G. Courbet, Le désespéré (Autoportrait) G. Courbet, The desperate man (Self-portrait)
R Programming Yang, Yufei. Normal distribution.
S-PLUS Lecture 2 Jaeyong Lee Department of Statistics Pennsylvania State University.
STAT 534: Statistical Computing Hari Narayanan
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Analyzing Local Properties Many local properties are important for the function of your protein –Hydrophobic regions are potential transmembrane domains.
Lecture #7 Page 1 Lecture #7 Agenda 1.VHDL Data Types Announcements 1.n/a ECE 4110– Digital Logic Design.
Digital Image Processing Introduction to M-function Programming.
STAT 534: Statistical Computing Hari Narayanan
+ Part I. + R Developed by Ross Ihaka and Robert Gentleman at the University of Auckland, NZ Open source software environment for statistical computing.
Introduction to Exploratory Descriptive Data Analysis in S-Plus Jagdish S. Gangolly State University of New York at Albany.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
Introduction to R Data Analysis and Calculations Katia Oleinik Research Computing Services Boston University
S-PLUS Lecture 4 Jaeyong Lee Pennsylvania State University.
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.
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)
Relational and Logical Operators EE 201 1C7-2 Spring 2012.
Working with R Marcin Krzystanek PhD student at Cancer Systems Biology group, CBS Technical University of Denmark.
Review > x[-c(1,4,6)] > Y[1:3,2:8] > island.data fishData$weight[1] > fishData[fishData$weight < 20 & fishData$condition.
16BIT IITR Data Collection Module If you have not already done so, download and install R from download.
Vectors and DataFrames. Character Vector: b
Computational Methods in Astrophysics Dr Rob Thacker (AT319E)
X is a matrix of size 4 x 2 (4 rows by 2 columns).
Working with data in R 2 Fish 552: Lecture 3. Recommended Reading An Introduction to R (R Development Core Team) –
Programming in R Intro, data and programming structures
R basics workshop Sohee Kang Math and Stats Learning Centre
R basics workshop J. Sebastián Tello Iván Jiménez
Ch.4 Data Manipulation.
Naomi Altman Department of Statistics (Based on notes by J. Lee)
The R Book Chapter 2: Essentials of the R Language Session 4.
R basics workshop Sohee Kang Math and Stats Learning Centre
البرمجة بلغة فيجول بيسك ستوديو
Lists in Python.
Data Analytics (CS40003) Programming with R Lecture #4
Vectors and DataFrames
R Course 2nd lecture.
R Course 1st Lecture.
Stat 251 (2009, Summer) Lab 2 TA: Yu, Chi Wai.
Data analysis with R and the tidyverse
Creating a dataset in R Instructor: Li, Han
R programming.
Presentation transcript:

Data Management Data Types R basic 11/11/2013

Data Types 1. Vector 2. Factor 3. Matrix 4. Array 5. List 6. Dataframe

1. Vector (1) > c(1,2,3,4,5) #Numbers [1] > c("a","b","c","d","e") #Strings [1] "a" "b" "c" "d" "e" > c(T,F,T,F) #Logicals [1] TRUE FALSE TRUE FALSE > numeric(5) [1] > logical(5) [1] FALSE FALSE FALSE FALSE FALSE > character(5) [1] "" "" "" "" ""

1. Vector (2) 1:5 [1] :1 [1] seq(1,5) [1] seq(1,5,by=.5) [1] rep(1,5) [1] rep(1:2,5) [1] length(x) # Get length of object x <- seq(1,5,by=.5) [1] 9 x[length(x)] # Select the last element. [1] 5.0

2. Factor > factor(c("yes","no","yes","maybe","maybe","no","no")) [1] yes no yes maybe maybe no maybe no no Levels: maybe no yes > factor(c("yes","no","yes","maybe","maybe","no","no"), ordered = T) [1] yes no yes maybe maybe no maybe no no Levels: maybe < no < yes > factor(c("yes","no","yes","maybe","maybe","no","no"), levels=c("no","maybe","yes"),ordered = T) [1] yes no yes maybe maybe no maybe no no Levels: no < maybe < yes

3. Matrix (1) > matrix(data = NA, nrow = 5, ncol = 5) [,1] [,2] [,3] [,4] [,5] [1,] NA NA NA NA NA [2,] NA NA NA NA NA [3,] NA NA NA NA NA [4,] NA NA NA NA NA [5,] NA NA NA NA NA > matrix(data = 1:15, nrow = 5, ncol = 5, byrow = T) [,1] [,2] [,3] [,4] [,5] [1,] [2,] [3,] [4,] [5,]

3. Matrix (2) > v1 <- 1:5 > v2 <- 5:1 > v2 [1] > cbind(v1,v2) v1 v2 [1,] 1 5 [2,] 2 4 [3,] 3 3 [4,] 4 2 [5,] 5 1 > rbind(v1,v2) [,1] [,2] [,3] [,4] [,5] v v

3. Matrix (3) > X<-matrix(data = 1:15, nrow = 5, ncol = 5, byrow = T) > dim(X) [1] 5 5 > nrow(X) [1] 5 > ncol(X) [1] 5 #Function t() transposes a matrix. > t(X) [,1] [,2] [,3] [,4] [,5] [1,] [2,] [3,] [4,] [5,]

3. Matrix (4) > a=matrix(2,2,2) > a [,1] [,2] [1,] 2 2 [2,] 2 2 > a = rbind(a,c("A","A")) > a [,1] [,2] [1,] "2" "2" [2,] "2" "2" [3,] "A" "A"

4. Array > z = array(1:27,dim=c(3,3,3)) > dim(z) [1] > z,, 1 [,1] [,2] [,3] [1,] [2,] [3,] 3 6 9,, 2 [,1] [,2] [,3] [1,] [2,] [3,] ,, 3 [,1] [,2] [,3] [1,] [2,] [3,] > z[,,3] [,1] [,2] [,3] [1,] [2,] [3,] > z[,3,3] [1] > z[3,3,3] [1] 27

5. List (1) > x <- c(1:4) > y <- FALSE > z <- matrix(c(1:4),nrow=2,ncol=2) > myList <- list(x,y,z) > myList [[1]] [1] [[2]] [1] FALSE [[3]] [,1] [,2] [1,] 1 2 [2,] 3 4

5. List (2) #By index number > a = list() > a list() > a[[1]] = "A" > a [[1]] [1] "A" > a[[2]]="B" > a [[1]] [1] "A" [[2]] [1] "B" #By name > a = list() > a$fruit = "Apple" > a $fruit [1] "Apple" > a$color = "green" > a $fruit [1] "Apple" $color [1] "green"

5. List (3) > a = list() > a[[1]] = "house" > a$park = "green's park" > a[[1]]$address = "1 main st." > a [[1]] [[1]][[1]] [1] "house" [[1]]$address [1] "1 main st." $park [1] "green's park"

6. DataFrame (1) > v1 = 1:5 > v2 = c(T,T,F,F,T) > df = data.frame(v1,v2) > df v1 v2 1 1 TRUE 2 2 TRUE 3 3 FALSE 4 4 FALSE 5 5 TRUE

6. DataFrame (2) > df[,1] [1] > df$v2 [1] TRUE TRUE FALSE FALSE TRUE > df = data.frame(foo=1:5,bar=c(T,T,F,F,T)) > df foo bar 1 1 TRUE 2 2 TRUE 3 3 FALSE 4 4 FALSE 5 5 TRUE