Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 171

4.8 Selected Data Interfaces

Оглавление

Most analysis will start with reading in data. This can be done from many types of electronic formats such as databases, spreadsheet, CSV files, fixed width text-files, etc.

Reading text from a file in a variable can be done by asking R to request the user to provide the file name as follows:

t <- readLines(file.choose())

file.choose()

or by providing the file name directly:

t <- readLines(“R.book.txt”)

readLines()

This will load the text of the file in one character string t. However, typically that is not exactly what we need. In order to manipulate data and numbers, it will be necessary to load data in a vector or data-frame for example.

In further sections – such as Chapter 15Connecting R to an SQL Database” on page 327 – we will provide more details about data-input. Below, we provide a short overview that certainly will come in handy.

The Big R-Book

Подняться наверх