我正在尝试使用read_excel
(这是xlsx
文件)将Excel文件读入R,我的列包含字母和数字,例如P765876
之类的内容。这些列也包含只有234654
的数字的单元格,所以当它读入R
时,它读取为未知(不是字符或数字),但这意味着它给出了任何具有字母和将值NA
编号,我该如何正确阅读?
目前我的代码是
tenant<-read_excel("C:/Users/MPritchard/Repairs Projects/May 2017/Tenant Info/R data 1.xlsx")
答案 0 :(得分:0)
还建议使用col_types参数,通过将其指定为“text”,您应该避免通过强制引入NA。所以你的代码就像:
tenant<-read_excel("C:/Users/MPritchard/Repairs Projects/May 2017/Tenant Info/R data 1.xlsx", col_types = "text")
如果这解决了您的问题,请告诉我。 问候, /迈克尔
答案 1 :(得分:0)
不是一个答案,但对于评论来说太多了......
1:
> library(xlsx)
> tenant <- read.xlsx("returns.xlsx", sheetIndex = 1)
> str(tenant)
'data.frame': 9 obs. of 3 variables:
$ only_integer: num 1 2 34 5 546931 ...
$ int_char : Factor w/ 9 levels "2545","2a","2d",..: 6 4 9 3 5 1 7 2 8
$ only_char : Factor w/ 6 levels "af","dd","e",..: 2 1 5 6 3 2 4 3 1
2:
> library(readxl)
> tenant2 <- read_excel("returns.xlsx")
> str(tenant2)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 9 obs. of 3 variables:
$ only_integer: num 1 2 34 5 546931 ...
$ int_char : chr "d5" "5" "ff2ad2f" "2d" ...
$ only_char : chr "dd" "af" "h" "ha" ...
列int_char
是两者的混合,以数字或字符开头/结尾