当前位置:网站首页>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 .
边栏推荐
- Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
- How do std:: function and function pointer assign values to each other
- The solution of permission denied
- Alibaba cloud server connection intranet operation
- C语言数组
- When synchronized encounters this thing, there is a big hole, pay attention!
- Iterm tab switching order
- 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
- Openssl3.0 learning 20 provider KDF
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 5
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23](/img/72/a80ee7ee7b967b0afa6018070d03c9.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
![Cadence physical library lef file syntax learning [continuous update]](/img/d5/0671935b074e538a2147dbe51a5a70.jpg)
Cadence physical library lef file syntax learning [continuous update]

【数据聚类】第四章第一节3:DBSCAN性能分析、优缺点和参数选择方法

R语言--readr包读写数据
![Entitas learning [iv] other common knowledge points](/img/1c/f899f4600fef07ce39189e16afc44a.jpg)
Entitas learning [iv] other common knowledge points

Abnormal mode of ARM processor

Exness: positive I win, negative you lose
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22](/img/e0/21367eeaeca10c0a2f2aab3a4fa1fb.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22

The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history

How to realize the function of Sub Ledger of applet?
随机推荐
The solution of permission denied
记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
Servlet learning notes
Experiment 7. IPv6
World document to picture
nn. Exploration and experiment of batchnorm2d principle
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
priority_ queue
Lecture 9
Leetcode: 408 sliding window median
When synchronized encounters this thing, there is a big hole, pay attention!
22 API design practices
Xshell's ssh server rejected the password, failed to skip publickey authentication, and did not register with the server
Global and Chinese market of piston rod 2022-2028: Research Report on technology, participants, trends, market size and share
Communication tutorial | overview of the first, second and third generation can bus
[notes] in depth explanation of assets, resources and assetbundles
Decrypt the advantages of low code and unlock efficient application development
The most robust financial products in 2022
13、 C window form technology and basic controls (3)