Mrs. Friday
Mrs. Friday

Reputation: 27

Import .xlsx with rio

Good evening,

I have a problem concerning my import with the package rio. I have given an excel-sheet (1 column, 1000 rows) with the numerics starting in the first row! And that is basically my problem. I know how an import with rio works and that rio interpretants the first row always as a character (thinking of it as the heading). But in my given data, the first row doesn’t have any heading, it starts right away with the numerics. So my question is basically: How do I need to change my command so that rio reads the first row as a numeric and not as a heading/character? My command so far:

library(rio)
setwd(…)
A12<-import("A12_daten.xlsx")

Important: It is an exercise I have to do for college. And it is given that I have to solve the problem with the package rio!

Thank for your help & time stay healthy

Upvotes: 0

Views: 1656

Answers (2)

Waldi
Waldi

Reputation: 41260

rio package uses readxl::read_excel to read Excel files.

Hence, you can use col_names argument from read_excel.

A12 <- import("A12_daten.xlsx", col_names = F)

Upvotes: 2

alias_z
alias_z

Reputation: 1

I just discovered the same issue but I solved it today. The easiest way is to add an empty row before the first row.

If you have multiple sheets to read: The import function read the first row as a column name, so you can just convert the name into numeric and then rbind to the rest.

A12 <- import('A12_daten.xlsx')
rbind(as.numeric(names(A12)), A12)

Upvotes: 0

Related Questions