Import Excel Data into R Dataframe
In our previous tutorial, we learned to read an excel file in R using readxl package. In this tutorial, we will learn how to import Excel data into an R Dataframe.
In certain scenarios, your input data might come in an XLS or XLSX Excel files. Then you need to load the data from Excel file into R.
To read Excel Data into an R Dataframe, we first read Excel data using read_excel() and then pass this excel data as an argument to data.frame() function.
Reference: Read Excel File Data in R
> exceldata = read_excel("C:\\tutorialkart\\r\\sample.xlsx")
> dfdata = data.frame(exceldata)
> dfdata
ID Name Salary
1 22 John 25000
2 41 Samantha 30000
3 15 Ron 37000
4 63 Rick 15000
5 87 Gary 56000
In the above example, when we read excel data using read_excel() function, the excel data is read into a tibble.
You can perform the data operations on a tibble just like a dataframe.
If you would like to access the data in an R Dataframe, you can use data.frame() function as shown in the above example.