Import excel file to R studio

Hi All,
I am facing issue while importing excel file (.xls), I installed (RCPP) packages then the file was displayed in the file pane, but I cannot manipulate it and view it as a table.
This is what I wrote in console:
View(Prod)
data("Prod")

You have to read the file using a function from one of the packages that facilitate using Excel files. First run

library(readxl)

If you get an error about there being no such package, run

install.packages("readxl")

then run the library() function I showed above.
You can now run (assuming your file is named Prod.xls)

DF <- read_excel("Prod.xls")

Your data will now be in a data frame named DF. I have made some assumptions in these instructions. If you get any errors, post the error message here and we'll figure out how to adjust the code.

1 Like

Thanks for the quick response, I have another issue: now the table being viewed but I cannot manipulate it or filter, let's say I want to use (colnames) or str (function) it gives me this message:

colnames(prod)
NULL
library(readxl)
colnames(prod)
NULL
str(prod)
function (..., na.rm = FALSE)

If you ran the code

DF <- read_excel("Prod.xls")

then to see the column names you need to run

colnames(DF)

Note that I am assuming your file is named Prod.xls. Be sure to use your actual file name.

I know, it is silly from me but it gave me this message while I have imported the excel file and this is what I wrote in R file:
install.packages("tidyverse")
install.packages("readxl")
library(readxl)

data("Prod")
View(prod)
DF <- read_excel("Prod.xls")

this is the message:

View(prod)

DF <- read_excel("Prod.xls")
Error in read_excel("Prod.xls") : could not find function "read_excel"

What happens if you run

readxl::read_excel("Prod.xls")

eadxl::read_excel("Prod.xls")
Error: path does not exist: ‘Prod.xls’

So there is no file named Prod.xls in your working directory. You see which directory is the current working directory with the command

getwd()

You can see the files in that directory with

dir()

If the file you want is in the current working directory, you probably have a typo in the name. Might it be Prod.xlsx? If the file you want is not in the current working directory, you can load it by including the directory path in the read_excel() function. For example, to load a file named Prod.xlsx that is on my desktop, I would run

readxl::read_excel("C:/Users/fjcc/Desktop/Prod.xlsx")

That is a Windows path. On Linux or MacOS, it would look quite different.

The fact that running readxl::read_excel() does not throw the "could not find function" error but running plain read_excel() does throw the error shows that you did not load the readxl package successfully with library(readxl). Was there any error message when you ran that?

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.