当前位置:网站首页>R language -- readr package reads and writes data
R language -- readr package reads and writes data
2022-07-04 12:36:00 【Eat two bites at a time】
List of articles
Preface
When you try your best ,read.csv and read.table Still unable to read data , Maybe you can try readr In bag read_table
,read_csv
Such as function . Try it !
I am a very single-minded person ( lazy ) People who , Although some people on the Internet say readr Reading data in the package is faster than traditional functions , I have always used the traditional method , I haven't tried readr package .
Until today, the senior brother of the laboratory told me that he r Language cannot read data , I tried for a long time , Many parameters are used , I also searched online for a long time , But it didn't work ( Maybe I'm stupid ), I just tried to use this package , The result is , There are not too many parameters passed in , Too cattle , I cried to death .
So record the whole process and compare the speed of reading and writing data between it and traditional functions .
One 、 Find the problem
I won't upload the data , Maybe you won't encounter this kind of problem .. Mainly look at the error report !
At first, I thought it might be the problem of data coding , then :
a <- read.csv(file = 'seerv.csv',header = T,fill = T,check.names = F,fileEncoding = 'GBK')
a <- read.csv(file = 'seerv.csv',header = T,fill = T,check.names = F,fileEncoding = 'UTF-8')
About the inside header,fill,check.names,encoding,fileEncoding And other parameters I have tried ( In many cases , The change of these parameters can smoothly read the data ), To no avail .( Want to try and communicate further , I can send some data privately )
Two 、 To analyze problems
In addition to changing some parameters , I also want to enjoy it read.table Source code , It turns out that the inner part may be quoted C Language , However, I only learned C Language foundation , So the way to solve the problem through the source code is broken again .
adopt read.table
, No parentheses . perhaps edit(read.table)
You can see the code .
This is part of the source code :
Error message “no lines available in input” Appear suddenly , I know where there may be a problem , But I have no way to further analyze the reason .
3、 ... and 、 solve the problem
Finally, I searched the Internet ,R Language reading data , Discovery can be achieved by readr Package read / write data , Then I successfully read .
Then I , I am lazy , I really don't want to understand why the traditional method will report an error when reading that data , Let's call it a day .
library(readr)
a <- read_csv(file = 'seer.csv')
I *, In the past, it was not used check.names=F Parameter words , Traditional methods encode some special symbols as .( spot ), and read_csv
There is no need to use anything check.names Parameters .
Four 、 Read/write speed
Last , Many people say that this package can read and write data quickly , I'll test the difference in reading and writing speed between it and traditional functions , How big is the difference .
d <- matrix(rnorm(25000000),nrow = 5000,ncol = 5000)
d <- as.data.frame(d)
t1 <- Sys.time()
write.csv(d,file = 'write.csv.csv')
Sys.time()-t1
t1 <- Sys.time()
write_csv(d,file = 'write_csv.csv')
Sys.time()-t1
t1 <- Sys.time()
a <- read.csv(file = 'write.csv.csv')
Sys.time()-t1
t1 <- Sys.time()
b <- read_csv(file = 'write_csv.csv')
Sys.time()-t1
Write data :
55.7 second vs 1.7 second
write_csv: The speed of write.csv: Close to 30 times .
Read in the data :
1.3 branch vs 20.3 second
read_csv: The speed of reading data is read.csv Close to 3 times .
Compare only one data set with a pair of functions , Although the result speed gap may not be accurate , but readr The reading and writing speed of the package is really fast , I can't test every data .
Here is just a simple comparison of the reading and writing speed of a pair of functions
The parameters in the function are not mentioned .
summary
I don't want to understand why the data can't be read , As long as you can read it , Otherwise, elder martial brother tortured me . Ha ha ha !
Make complaints
Say a wordless thing I met today , So and so for the purchase code , The code can't run anymore , Wrong report , Send me code and data , I ran his code and found , There is no preset gene name in the gene matrix , Just change a gene to study ( Maybe the instructions are not detailed enough ). And then there's no then , Not a word of thanks .
A little white , Welcome criticism .
If you can solve the previous read.csv The problem of , Talk to me in private , I'll give you some data .
边栏推荐
- Anti clockwise rotation method of event arrangement -- PHP implementation
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 5
- Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- World document to picture
- 01. Basics - MySQL overview
- When synchronized encounters this thing, there is a big hole, pay attention!
- Langue C: trouver le nombre de palindromes dont 100 - 999 est un multiple de 7
- C语言数组
- Global and Chinese market of ice water machines 2022-2028: Research Report on technology, participants, trends, market size and share
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
猜你喜欢
It's hard to hear C language? Why don't you take a look at this (V) pointer
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
nn. Exploration and experiment of batchnorm2d principle
The database connection code determines whether the account password is correct, but the correct account password always jumps to the failure page with wrong account password
C语言数组
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
How to realize the function of Sub Ledger of applet?
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
vim 出现 Another program may be editing the same file. If this is the case 的解决方法
MySQL performance optimization index
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
Abnormal mode of ARM processor
8.8.1-PointersOnC-20220214
In 2022, financial products are not guaranteed?
Flet教程之 按钮控件 ElevatedButton入门(教程含源码)
03_ Armv8 instruction set introduction load and store instructions
Lvs+kept highly available cluster
The most robust financial products in 2022
ASP. Net razor – introduction to VB loops and arrays
Global and Chinese markets for soluble suture 2022-2028: Research Report on technology, participants, trends, market size and share
C语言:围圈报号排序问题
Global and Chinese market of cardiac monitoring 2022-2028: Research Report on technology, participants, trends, market size and share
PKCs 5: password based cryptography specification version 2.1 Chinese Translation
Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
The solution of permission denied
MYCAT middleware installation and use
Hongke case study on storm impact in coastal areas of North Carolina using lidar
Bottom Logic -- Mind Map
TCP slicing and PSH understanding
IIS error, unable to start debugging on the webserver