Input Data in R using c() and scan() Functions

There are many ways to input data into R and S Language. Here, I will concentrate only on typing data directly at the keyboard using c() and scan() function.

The traditional statistical computer software such as Minitab, SPSS, and SAS, etc., are designed to transform rectangular datasets (a dataset whose rows represent the observations and column represent the variables) into printed reports and graphs. However, R and S languages are designed to transform data objects into other data objects (such as reports, and graphs).

S and R language both supports rectangular datasets, in the form of data frames and in other variety of data structures. Here we will learn to know about data in R in order to work efficiently as a statistical data analyst.

There are many ways to input data in R and S-Plus. Let us learn typing data directly at the keyboard.

The best choice to enter small datasets directly at the keyboard. Remember that it is impractical to enter a large data set directly at the keyboard.

Let use the c() function to enter the a vector of numbers directly as:

x <- c(1, 3, 5, 7, 9)
char <- c('a', 'b', 'c', 'd')

Note that the character strings can be directly inputted in single or double quotation marks. For example, "a" and 'a' both are equivalent.

It is also very convenient to use the scan() function, which prompts with the index of the next entry.  Consider the example,

xyz <- scan()
1: 10 20 30 35
5: 40 35 25
8: 9 100 50
Read 10 items</span>

The number before the colon on each of the inputted lines is the index of the next data entry point (observation) to be entered. Note that entering a blank line terminates the scan() function input behaviour.

Click the following links to learn about data entry (import and export internal and external data) in R Language