当前位置:网站首页>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 .
边栏推荐
- template<typename MAP, typename LIST, typename First, typename ... Keytypes > recursive call with indefinite parameters - beauty of Pan China
- First knowledge of spark - 7000 words +15 diagrams, and learn the basic knowledge of spark
- Ternsort model integration summary
- Memory computing integration: AI chip architecture in the post Moorish Era
- Complementary knowledge of auto encoder
- Abnormal mode of ARM processor
- CSDN documentation specification
- [notes] in depth explanation of assets, resources and assetbundles
- Translation D29 (with AC code POJ 27:mode of sequence)
- 记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
猜你喜欢
Ternsort model integration summary
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
Bottom Logic -- Mind Map
Clion configuration of opencv
Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
Awk getting started to proficient series - awk quick start
2022, 6G is heating up
Leetcode: 408 sliding window median
记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
How to judge the advantages and disadvantages of low code products in the market?
随机推荐
C語言:求100-999是7的倍數的回文數
Complementary knowledge of auto encoder
Azure solution: how can third-party tools call azure blob storage to store data?
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
Btrace tells you how to debug online without restarting the JVM
C language memory layout
Classification and application of AI chips
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
It's hard to hear C language? Why don't you take a look at this (V) pointer
A few words explain redis cache penetration, breakdown, avalanche, and redis sentinel
Ternsort model integration summary
SAP ui5 date type sap ui. model. type. Analysis of the display format of date
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
2022, 6G is heating up
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
Method of setting default items in C # ComboBox control code
Decrypt the advantages of low code and unlock efficient application development
Global and Chinese markets of digital PCR and real-time PCR 2022-2028: Research Report on technology, participants, trends, market size and share
What if the chat record is gone? How to restore wechat chat records on Apple Mobile