Keyboard Input

Usually you will obtain a data frame by importing it from SAS , SPSS , Excel , Stata, a database, or an ASCII file. To create it interactively, you can do something like the following.

# create a data frame from scratch
age <- c(25, 30, 56)
gender <- c("male", "female", "male")
weight <- c(160, 110, 220)

mydata <- data.frame(age,gender,weight)

You can also use R's built in spreadsheet to enter the data interactively, as in the following example.

# enter data using editor
mydata <- data.frame(age=numeric(0), gender=character(0), weight=numeric(0))
mydata <- edit(mydata)
# note that without the assignment in the line above,
# the edits are not saved!

To Practice

To practice importing data in R, try the first chapter of this course from DataCamp