Creating a Data Frame
A Data Frame is a two-dimensional labeled data structure. It may consist of fields/columns of different types. It simply looks like a table in SQL or like an excel worksheet. In R, to create a Data Frame use data.frame() method. The syntax to create a data frame is given as-
data <- data.frame(columnName1=c( data1,data2,...), ........... columnNameN=c(data1,data2,...))
Example:
In this example let’s look into how to create a Data Frame in R using data.frame() method.
R
# create a data frame stats <- data.frame (player= c ( 'A' , 'B' , 'C' , 'D' ), runs= c (100, 200, 408, NA ), wickets= c (17, 20, NA , 5)) print ( "stats Dataframe" ) stats |
Output
"stats Dataframe" player runs wickets 1 A 100 17 2 B 200 20 3 C 408 NA 4 D NA 5
How to create, index and modify Data Frame in R?
In this article, we will discuss how to create a Data frame, index, and modify the data frame in the R programming language.
Contact Us