Creating a dataset in R Instructor: Li, Han

Slides:



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

An Introduction to R: Logic & Basics. The R language Command line Can be executed within a terminal Within Emacs using ESS (Emacs Speaks Statistics)
R for Macroecology Aarhus University, Spring 2011.
Introduction to arrays
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.
Maths for Computer Graphics
R for Research Data Analysis using R Day1: Basic R Baburao Kamble University of Nebraska-Lincoln.
Introduction to Exploratory Descriptive Data Analysis in S-Plus Jagdish S. Gangolly State University of New York at Albany.
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.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week2: Data Structure, Types and Manipulation in R.
3. Functions and Arguments. Writing in R is like writing in English Jump three times forward Action Modifiers.
Arko Barman with modification by C.F. Eick COSC 4335 Data Mining Spring 2015.
Exploring Engineering Chapter 3, Part 2 Introduction to Spreadsheets.
Data Objects in R Vector1 dimensionAll elements have the same data types Data types: numeric, character logic, factor Matrix2 dimensions Array2 or more.
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.
R Programming Yang, Yufei. Normal distribution.
The introduction of Microsoft Excel. Spreadsheet Basic.
R packages/libraries Data input/output Rachel Carroll Department of Public Health Sciences, MUSC Computing for Research I, Spring 2014.
Introduction to Excel The Basics of Microsoft Excel 2010.
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.
R Introduction, Data Structures. An Excellent R Book (among many others) R in Action Data Analysis and Graphics with R Robert I. Kabacoff
Excel Basics. Differentiating between worksheets and spreadsheets Differentiating between workbooks and worksheets.
Introduction to Exploratory Descriptive Data Analysis in S-Plus Jagdish S. Gangolly State University of New York at Albany.
Section 9-1 An Introduction to Matrices Objective: To perform scalar multiplication on a matrix. To solve matrices for variables. To solve problems using.
S-PLUS Lecture 4 Jaeyong Lee Pennsylvania State University.
Data & Graphing vectors data frames importing data contingency tables barplots 18 September 2014 Sherubtse Training.
Computer Science 121 Scientific Computing Winter 2016 Chapter 4 Collections and Indexing.
Data Management Data Types R basic 11/11/2013. Data Types 1. Vector 2. Factor 3. Matrix 4. Array 5. List 6. Dataframe.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
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.
Working with data in R 2 Fish 552: Lecture 3. Recommended Reading An Introduction to R (R Development Core Team) –
Arko Barman COSC 6335 Data Mining Fall  Free, open source statistical analysis software  Competitor to commercial softwares like MATLAB and SAS.
Advanced Excel Topics – Arrays
13.4 Product of Two Matrices
Programming in R Intro, data and programming structures
R basics workshop Sohee Kang Math and Stats Learning Centre
R programming language
Introduction to R Samal Dharmarathna.
Arko Barman COSC 6335 Data Mining Fall 2014
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
The R Book Chapter 2: Essentials of the R Language Session 6.
Welcome to Math’s Tutorial Session-3 Data handling
R basics workshop J. Sebastián Tello Iván Jiménez
R Data Structures.
EGR 115 Introduction to Computing for Engineers
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
Introduction to R Studio
2) Platform independent 3) Predefined functions
Uploading and handling databases
R basics workshop Sohee Kang Math and Stats Learning Centre
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
Lab 1 Introductions to R Sean Potter.
Use of Mathematics using Technology (Maltlab)
CSCI N207 Data Analysis Using Spreadsheet
D2 Indices and matrices Matrix representation in computer systems:
Statistics 540 Computing in Statistics
Vectors and DataFrames
Multidimensional array
Introduction to R v
Multi-Dimensional Arrays
EECE.2160 ECE Application Programming
R Course 1st Lecture.
Arrays in MatLab Arrays can have any number dimensions
Working with Arrays in MATLAB
Introduction to Matrices
Announcements.
Presentation transcript:

Creating a dataset in R Instructor: Li, Han chapter 2 Creating a dataset in R Instructor: Li, Han

Contents objects: vector, matrix, data frame, factor, list... input data from external files: text, Excel...

Object name types of objects: vector, matrix, array, data frame, factor, list creation assign a value create a blank object, for example, list()

Different classes of objects

Assignment “<-” used to indicate assignment x <- 2 x <- c(1,2,3,4,5,6,7) x <- 1:7 x <- seq(from=1,to=10,by=2) x <- seq(1,10,2) Note that we could also use "=" to assign the value.

Naming Convention must start with a letter (A-Z or a-z) can contain letters, digits (0-9), and/or periods “.” case-sensitive mydata is different from MyData do not use underscore “_”

Vector a one-dimensional array that can hold numerical, character or logical data x <- c(...) a <- c(1, 2, 5, 3, 6, -2, 4) b <- c("one", "two", "three") d <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)

How to refer to the element of a vector x[i]: i-th element x[vec]: the elements whose positions are specified in vec

Matrix a two-dimensional array that each element has the same mode (numeric, character, or logical) mymatrix <- matrix(vector, nrow=?, ncol=?, byrow=TRUE/FALSE, dimnames=?)

How to refer to the elements of a matrix x[i,j]: i-th, j-th element x[i, ]: i-th row x[ ,j]: j-th column x[vec1, vec2]: a submatrix

Array Array is similar to matrix, but has more than two dimensions myarray <- array(vector, dimensions=?, dimnames=?)

Data frame Data frame is more general than a matrix because its columns can have different kinds of data. mydata <- data.frame(col1, col2,...)

How to refer to elements of a data frame? x[vec]: columns specified in vec x[variable.names] x$variable.name

Factor Factor is an ordinal or unordinal nominal variable.

List List is an ordered object that contains different kinds of sub-objects, for example, vectors, matrices, data frames and even lists. mylist <- list(object1, object2,...) How to refer to the elements of a list x[[i]]:i-th compoent x$variable.name

How does R deal with different objects

Attributes of an object mode(object): numeric, character, logical length(object): number of elements in an object dim(object): dimension of a matrix/data frame class(object): type of an object str(object):structure of an object names(object):names of components in an object

Import data If we already have a data file, how can we directly import it into R instead of manually creating all its objects?

Import a data from a text file mydataframe <- read.table(file, header=TRUE/FALSE, sep=?, row.names=?)

studentgrades.txt StudentID, First, Last, Math, Science, Social Studies 011, Bob, Smith, 90, 80, 67 012, Jane, Weary, 75, , 80 010, Dan, "Thorn, III", 65, 75, 70 040, Mary, "O'Leary", 90, 95, 92

grades <- read. table("studentgrades grades <- read.table("studentgrades.txt", header=TRUE, sep=",", row.names="StudentID")

Import data from an excel file The “xlsx” package can be used to access spreadsheets in excel format. Be sure to download and install the package before first use. The read.xlsx() function imports a worksheet from an XLSX file into a data frame.

studentgrades2.xlsx

Import data from an excel file install.packages("xlsx") library(xlsx) workbook <- “D:/studentgrades2.xlsx” grades2 <- read.xlsx(workbook, 1)

Practice Try all the examples by yourself. Check the attributes of different objects. Try to input text/excel files.