Import Data

One easy method of getting data into S-PLUS for plotting and analysis is to import the data file.

S-PLUS also allows you to export your data sets and graphs to many file formats for printing and for use in other applications.

When you are importing most file types, typically you only need to specify the file name and file type, and the file is imported into a new data set and opened in a Data window, using default settings. You can specify your own settings in the Filter page of the Import Data dialog.

To open the Import Data dialog, Choose File __image\arrow5.gif Import Data. The dialog shown below appears.

Data Page

In the Import Data dialog, the Data page has a section that allows you to navigate to a particular directory and file to be imported.

__image\import1.gif

In the Import Data dialog, the Data page has the following options:

File

File Name

Select the name of the file to import.

File Format

Select the format of the file to import.

Data Set Name

Save As

Enter the name for the object in which to save the results of the analysis.

Filter Page

In the Import Data dialog, the Filter page allows you to subset the data you import. By specifying a query, or filter, you gain additional functionality, such as taking a random sampling of the data. Use the examples and explanation of the filter syntax described below to create your statement. A blank filter is the default and results in all data being imported.

__image\import2.gif

In the Import Data dialog, the Filter page has the following options:

Select Columns

Keep Columns

A character vector of variable names, or numeric vector of column numbers, to be imported from the data file. Only one keep and drop can be specified.

Drop Columns

A character vector of variable names, or numeric vector of column numbers, not to be imported from data file. Only one of keep and drop can be specified.

Select Rows

Filter Rows

A character string containing a logical expression for selecting the rows to be included in the return value.

Format Page

__image\import3.gif

In the Import Data dialog, the Format page has the following options:

Factor Columns

Import Strings as Factors

A logical value, if TRUE then strings are converted to factors when imported.

Sort Factor Levels

A logical value, if TRUE then levels for any factors created from strings will be sorted.

Labeled Values as Numbers

A logical value, if TRUE then SAS and SPSS variables with labels will be imported as numbers.

Text Files

Column Delimiter

A character string specifying the character to use as a delimiter in an ASCII input file.

Format String

Specify the data types of the imported columns.

Century Cutoff

A numeric value, dates with two digit years will be assigned to the 100 year span that starts with this value.

Range Page

In the Import Data dialog, the Range page allows you to filter data from rows and columns when importing data from a spreadsheet.

__image\import4.gif

In the Import Data dialog, the Range page has the following options:

Column Range

Start Column

An integer specifying the starting column in the source. Only used for spreadsheets.

End Column

An integer specifying the end column in the source. The default of -1 means the last column. Only used for spreadsheets.

Row Range

Start Row

An integer specifying which row to start reading values from. Only used for spreadsheets.

End Row

An integer specifying the last row to read values from. Only used for spreadsheets.

Names

Row of Col Names

An integer specifying the row that contains the names for the columns. Only used for spreadsheets.

Col of Row Names

An integer denoting which column is to be used as the row names in the resulting data frame. If specified, that column is dropped from the resulting data frame.

Page

Page Number

The page number of the spreadsheet.