Professional Documents
Culture Documents
Data Frames in R
Data Frames in R
➢ Data Frames are generic data objects of R which are used to store the tabular data.
➢ However, it differs from a matrix in that each column of a matrix can be of the different data
types.
➢ Or data frames are the heterogeneous analogs of matrices for two-dimensional data.
print(Data_Frame)
emp_id = c (1:5),
"2015-03-27")),
stringsAsFactors = FALSE
print(emp.data)
Summary of data in the data frame
In R data frame, the statistical summary and nature of the data can be obtained by
applying summary() function.
print(summary(Data_Frame))
emp_id = c (1:5),
"2015-03-27")),
stringsAsFactors = FALSE
print(summary(emp.data) )
# Extract Specific columns.
print(result)
print(result)
# Extract 3rd and 4th row with 2nd and 3rd column.
print(result)
# Extract 3rd and 5th row with 2nd and 4th column.
print(result)
Add Rows
Add Columns
Use the c() function to remove rows and columns in a Data Frame
print(Data_Frame)
New_row_DF
New_col_DF
Data_Frame_New
#dim() function to find the number of rows and columns in a Data Frame
dim(Data_Frame)
#ncol() function to find the number of columns and nrow() to find the number of rows
ncol(Data_Frame)
nrow(Data_Frame)
Use the rbind() function to combine two or more data frames in R vertically
And use the cbind() function to combine two or more data frames in R horizontally
New_Data_Frame
Data_Frame4<- data.frame(
New_Data_Frame1<-cbind(Data_Frame3, Data_Frame4)
print(New_Data_Frame1)
Data_Frame3<- data.frame(
Data_Frame3$Salary = c(4000,5000,6000)
New_Data_Frame<-Data_Frame3
print(New_Data_Frame)