Importing Data into R



Similar documents
Getting your data into R

Using R for Windows and Macintosh

Reading and writing files

Step 2: Save the file as an Excel file for future editing, adding more data, changing data, to preserve any formulas you were using, etc.

Tutorial 2: Reading and Manipulating Files Jason Pienaar and Tom Miller

Importing Data into SAS

How to Import Data into Microsoft Access

NCSS Statistical Software

The Saves Package. an approximate benchmark of performance issues while loading datasets. Gergely Daróczi

R data import and export

Xerox Standard Accounting Import/Export User Information Customer Tip

EXCEL IMPORT user guide

Introduction to RStudio

Installing R and the psych package

SPSS for Windows importing and exporting data

Using Big Datasets in Stata

Designed by Jason Wagner, Course Web Programmer, Office of e-learning ZPRELIMINARY INFORMATION... 1 LOADING THE INITIAL REPORT... 1 OUR EXAMPLE...

Dataframes. Lecture 8. Nicholas Christian BIOST 2094 Spring 2011

Using Computer Programs for Quantitative Data Analysis

Service Desk R11.2 Upgrade Procedure - How to export data from USD into MS Excel

Home Loan Manager Pro 7.1

Using the Advanced Tier Data Collection Tool. A Troubleshooting Guide

2. The Open dialog box appears and you select Text Files (*.prn,*.txt,*.csv) from the drop-down list in the lower right-hand corner.

How to Download Census Data from American Factfinder and Display it in ArcMap

How To Write A File System On A Microsoft Office (Windows) (Windows 2.3) (For Windows 2) (Minorode) (Orchestra) (Powerpoint) (Xls) (

Setting up Auto Import/Export for Version 7

NAIP Consortium Strengthening Statistical Computing for NARS SAS Enterprise Business Intelligence

Choosing the Best Method to Create an Excel Report Romain Miralles, Clinovo, Sunnyvale, CA

FrontStream CRM Import Guide Page 2

jexcel plugin user manual v0.2

Importing from Tab-Delimited Files

Introduction to IBM Watson Analytics Data Loading and Data Quality

Table of Contents. Table of Contents 3

How to use MS Excel to regenerate a report from the Report Editor

Methodologies for Converting Microsoft Excel Spreadsheets to SAS datasets

User Manual - Sales Lead Tracking Software

SPSS: Getting Started. For Windows

Generating a Custom Bill of Materials

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Creating CSV Files. Recording Data in Spreadsheets

Importing and Exporting With SPSS for Windows 17 TUT 117

Microsoft Access Rollup Procedure for Microsoft Office Click on Blank Database and name it something appropriate.

Coupling Microsoft Excel with NI Requirements Gateway

Downloading Your Financial Statements to Excel

Advanced Excel 10/20/2011 1

USING MS OUTLOOK WITH FUS

Intro to Mail Merge. Contents: David Diskin for the University of the Pacific Center for Professional and Continuing Education. Word Mail Merge Wizard

How To Use Optimum Control EDI Import. EDI Invoice Import. EDI Supplier Setup General Set up

Basics Series-4004 Database Manager and Import Version 9.0

Ad Hoc Reporting: Data Export

Workshop Tutorial Importing XY Data in GIS

CloudCTI Recognition Configuration Tool Manual

UDW+ Quick Start Guide to Functionality 2013 Version 1.1

How To Read Data Files With Spss For Free On Windows (Spss)

Bulk Upload Tool (Beta) - Quick Start Guide 1. Facebook Ads. Bulk Upload Quick Start Guide

GUIDE TO REDCAP EXPORTED FILES

Salary. Cumulative Frequency

Choose the Reports Tab and then the Export/Ad hoc file button. Export Ad-hoc to Excel - 1

SAP Predictive Analysis Installation

R FOR SAS AND SPSS USERS. Bob Muenchen

QUALTRICS TIPS AND TRICKS FOR UNC-CH USERS

A Short Guide to R with RStudio

Introduction to IBM SPSS Statistics

How To Connect Your Transactions To Quickbooks Online From Your Bank Or Credit Card Account On A Pc Or Mac Computer Or Ipa Device

Create a Pipe Network with Didger & Voxler

Tutorial 2 Online and offline Ship Visualization tool Table of Contents

MicroStrategy Desktop

Analyzing financial data

User Guide. Analytics Desktop Document Number:

Explore commands on the ribbon Each ribbon tab has groups, and each group has a set of related commands.

Flat Pack Data: Converting and ZIPping SAS Data for Delivery

GETTING STARTED WITH R AND DATA ANALYSIS

1 Topic. 2 Scilab. 2.1 What is Scilab?

Introduction. Why Use ODBC? Setting Up an ODBC Data Source. Stat/Math - Getting Started Using ODBC with SAS and SPSS

Introduction You can use the OpenTable Gifts Merchant Dashboard to see sales and other reporting for your online gift cards.

UTILITIES BACKUP. Figure 25-1 Backup & Reindex utilities on the Main Menu

Importing Data from a Dat or Text File into SPSS

Basic Use of the SPC Feature on 1100R+/H+ Testers

BMV-602 Data Link Manual

Chapter 24: Creating Reports and Extracting Data

Pharmacy Affairs Branch. Website Database Downloads PUBLIC ACCESS GUIDE

Introduction to SPSS 16.0

Introduction to R software for statistical computing

Using FileMaker Pro with Microsoft Office

Chapter 4 Displaying and Describing Categorical Data

MAIL MERGE TIPS FOR PC USERS

Introduction to PASW Statistics

Estimating a market model: Step-by-step Prepared by Pamela Peterson Drake Florida Atlantic University

USING OUTLOOK WITH ENTERGROUP. Microsoft Outlook

Improving Your Relationship with SAS Enterprise Guide

Tips on exporting your Oracle Apps reports to Excel. Introduction

Transcription:

1 R is an open source programming language focused on statistical computing. R supports many types of files as input and the following tutorial will cover some of the most popular. Importing from text (.txt) file: We ll begin with the simplest type of data set to import into R: the text file. When you import data into R, you re creating a data frame (a data type in R that can be easily manipulated and worked with). Every file type you import will be turned into a data frame by R. If your data file is a simple text file, this is the statement you would use: mydata <- read.table( c:/datafile.txt ) You will now have a data frame named mydata in R that you can call functions on, analyze, create graphs with, or otherwise manipulate to your heart s content. This is the most basic function call, but there are other options that are included. Say, for example, the first line of your data set contained column names. The above function call would have those column names be the first entry in your data set. To fix this and have the column names properly displayed you would use: mydata <- read.table( c:/datafile.txt, header=true) This will take the first row of your data file and correctly interpret it as the names of the columns in your data frame. If you have a data file where each row is separated by a character, such as &, for instance, you can use the sep option in this function call. mydata <- read.table( c:/datafile.txt, sep= & ) If you have a tab delimited data file, which are somewhat common, R has a special import function: mydata <- read.delim( c:/datafile.txt )

2 However, it s worth noting that read.delim is just a special case of read.table, and tab delimited files can also be imported via read.table with the sep option set as the tab character: mydata <- read.table( c:/datafile.txt, sep= \t ) There are many more options you can utilize with the read.table function if you have a data set that won t import properly or just want to format it in a different way (for example, there is a row.names option). If you have an interest or need of these additional options, use the following command:?read.table This command will bring up the help/documentation page for read.table and give you a detailed look at all the options available to you. Note that this syntax works for any function you want more information about in R. TROUBLESHOOTING TIP: If you re having issues with the file path, make sure you re using / when specifying the file location instead of \. Note that when copying and pasting a file path from Windows, \ will be used. For example: C:/myFiles/R/data will be a valid file path while C:\myFiles\R\data will result in an error.

3 Importing from excel (.xls,.xlsx) file: R has the ability to import data files from excel (.xls or.xlsx) files directly, however there are sometimes formatting issues that will lead to problems or errors with the import. Luckily there is a very quick and easy work around that excel provides: saving your excel sheet as a.csv file. I always recommend doing this, as it is much easier, faster, and will result in far less errors. The first step is to use Microsoft Excel to open the.xls or.xlsx file you with to import. Next, select save as from the file menu and save the file as a CSV (comma delimited) file as shown below: Now you simply need to use the following function call: mydata <- read.csv( c:/datafile.csv ) Note that the default setting in this case is that header = TRUE, so the column names from your excel file will be automatically incorporated into your R data frame. If you do not have column names in your excel file, just set header=false.

4 Importing from other Statistical Software: R also has the ability to import data files from other statistical software packages, such as Minitab, SPSS, STATA, SAS, Octave, and more. In this tutorial we will look at SAS and SPSS. Unlike read.table, read.delim, and read.csv, the functions needed to import the above file types aren t built into R, we will need to call a package that contains these functions: library( foreign ) This package should be included in most R installations. If the above command doesn t work, you can install the package to your machine via CRAN (the Comprehensive R Archive Network) with the install.packages function: install.packages( foreign ) After this command you will need to select a CRAN mirror to install from and then you will be able to call the library function to load the package as previously shown. Note that there are many useful R packages that can be downloaded in this way. For a full list, go to http://cran.r-project.org/. Now that we have the package loaded, let s import a data file from SAS. Currently, SAS datasets cannot be directly imported into R in any other format. Therefore, we recommend exporting the SAS dataset to either the.xpt format or to.csv format and then importing to R. To import a SAS data set into R, first step export the data from SAS as a SAS XPORT file. After that, we can simply use the following function: mydata <- read.xport( c:/datafile.xpt ) Importing data from SPSS is just as simple: mydata <- read.spss ( c:/datafile.spss ) One nice feature about importing SPSS data files is that factors (or categorical variables) are automatically coerced to factors when the data set is imported into R. Also note that

5 read.spss has a few options you can use. Use?read.spss if you desire information about them. The foreign package includes other functions like this for STATA (read.dta), Octave (read.octave), and others which are just as simple to use. For full details, type: help(package=foreign)