Enter data as a data frame
To enter data as a data frame in the R Language, we use the data.frame() function. The data.frame() function creates data frames that are tightly coupled collections of variables. These data frames are widely used as the fundamental data structure in the R Language. A single data frame can contain different vectors of different classes together thus it becomes one data structure for all the needs.
Syntax:
data_frame <- data.frame( column_name1 = vector1, column_name2 = vector2 )
where,
- column_name1, column_name2: determines the name for columns in data frame
- vector1, vector2: determines the data vector that contain data values for data frame columns.
Example: Basic data frame that contains one numeric vector and one character vector.
R
# create data frame data_frame <- data.frame ( id = c (1,2,3), name = c ( "geeks" , "for" , "geeks" ) ) # print dataframe, summary and its class print ( "Data Frame:" ) data_frame print ( "Class:" ) class (data_frame) print ( "Summary:" ) summary (data_frame) |
Output:
Data Frame: id name 1 1 geeks 2 2 for 3 3 geeks Class: "data.frame" Summary: id name Min. :1.0 Length:3 1st Qu.:1.5 Class :character Median :2.0 Mode :character Mean :2.0 3rd Qu.:2.5 Max. :3.0
How to Manually Enter Raw Data in R?
In this article, we will discuss how to manually enter raw data in the R Programming Language.
In the R Language, we work with loads of different datasets by importing them through a variety of file formats. But Sometimes we need to enter our own raw data in the form of a character vector, a data frame, or a matrix. There are multiple methods to enter the raw data manually in the R Language.
Contact Us