How to import Excel data in R language?

In R language, you can use the readxl package to import Excel data.

First, make sure the readxl package is installed. If not, you can install it using the following command:

install.packages("readxl")

Once the installation is complete, you can use the read_excel() function to import Excel data. For example, if you want to import data from an Excel file named data.xlsx, you can use the following code:

library(readxl)

data <- read_excel("data.xlsx")

In the above code, the first argument of the read_excel() function is the path of the Excel file to import. The imported data will be stored in a variable named data.

If there are multiple worksheets in the Excel file, you can use the sheet parameter to specify the worksheet you want to import. For example, to import the first worksheet, you can use the following code:

data <- read_excel("data.xlsx", sheet = 1)

To import a specific range of cells, you can use the range parameter. For example, to import the range of cells from A1 to C10, you can use the following code:

data <- read_excel("data.xlsx", range = "A1:C10")

The above is a simple example of importing Excel data using the readxl package, you can adjust the parameters according to your specific needs.

bannerAds