当前位置:网站首页>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 .
边栏推荐
- Data communication and network: ch13 Ethernet
- [Android reverse] function interception instance (③ refresh CPU cache | ④ process interception function | ⑤ return specific results)
- 16.内存使用与分段
- Global and Chinese market for naval vessel maintenance 2022-2028: Research Report on technology, participants, trends, market size and share
- LVS load balancing cluster deployment - Dr direct routing mode
- Practical dry goods: deploy mini version message queue based on redis6.0
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
- Iterm tab switching order
- Practice of retro SOAP Protocol
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
猜你喜欢

17.内存分区与分页

Ml and NLP are still developing rapidly in 2021. Deepmind scientists recently summarized 15 bright research directions in the past year. Come and see which direction is suitable for your new pit
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13](/img/29/49da279efed22706545929157788f0.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13

13、 C window form technology and basic controls (3)

netstat

Error: Failed to download metadata for repo ‘AppStream‘: Cannot download repomd. XML solution
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16](/img/c3/f3746b161012acc3751b2bd0b8f663.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16

Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)

How to use "bottom logic" to see the cards in the world?

LVS load balancing cluster deployment - Dr direct routing mode
随机推荐
Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
In 2022, financial products are not guaranteed?
Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
Unity performance optimization reading notes - explore performance issues -profiler (2.1)
Fastlane 一键打包/发布APP - 使用记录及踩坑
8.8.1-PointersOnC-20220214
Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
How to realize the function of Sub Ledger of applet?
Single spa, Qiankun, Friday access practice
昨天的事情想说一下
Error: Failed to download metadata for repo ‘AppStream‘: Cannot download repomd. XML solution
13、 C window form technology and basic controls (3)
VBA, JSON interpretation, table structure -json string conversion
2022, 6G is heating up
Servlet learning notes
Communication tutorial | overview of the first, second and third generation can bus
[notes] streamingassets
Method of setting default items in C # ComboBox control code
Uva536 binary tree reconstruction tree recovery
Unity performance optimization reading notes - Introduction (1)