fread

R语言data.table包fread读取数据

匿名 (未验证) 提交于 2019-12-02 23:48:02
R语言处理大规模数据速度不算快,通过安装其他包比如data.table可以提升读取处理速度。 案例,分别用read.csv和data.table包的fread函数读取一个1.67万行、230列的表格数据。 # 用read.csv读取数据timestart<-Sys.time() data <- read.csv("XXXXs.csv",header = T,stringsAsFactors = F) timeend<-Sys.time() runningtime<-timeend-timestart print(runningtime) # 返回 runningtime 结果: Time difference of 4.451127 secs timestart<-Sys.time() data1<-fread("XXXXs.csv",header = T,stringsAsFactors = F) timeend<-Sys.time() runningtime<-timeend-timestart print(runningtime)# 返回 runningtime 结果: Time difference of 0.9460249 secs 参考资料: https://zhuanlan.zhihu.com/p/22317779?refer=rdatamining

fgets() and fread() - What is the difference?

不问归期 提交于 2019-12-02 21:53:20
I understand the differences between fgets() and fgetss() but I don't get the difference between fgets() and fread() , can someone please clarify this subject? Which one is faster? Thanks! Pascal MARTIN fgets reads a line -- i.e. it will stop at a newline. fread reads raw data -- it will stop after a specified (or default) number of bytes, independently of any newline that might or might not be present. Speed is not a reason to use one over the other, as those two functions just don't do the same thing : If you want to read a line, from a text file, then use fgets If you want to read some data

using fwrite() & fread() for binary in/output

做~自己de王妃 提交于 2019-12-02 11:01:16
I'm using a large array of floats. After a lot of fiddling I've managed to write it to a binary file. When opening that file at a later time, the reading process only reads a couple of handfuls of floats (according to the return-value of fread(), and it's all values 0.0f). The reading is supposed to put the floats into an (the original) array, and it does not contain the original values. I'm using Code::Blocks and MinGW doing a program in the 32bit realm on a 64bit pc .. and I'm not very proficient on c/c++ and pointers. #include<...> const int mSIZE = 6000 ; static float data[mSIZE*mSIZE] ;

fread'ing and fwrite'ing a structure that contains pointers [duplicate]

前提是你 提交于 2019-12-02 10:28:01
This question already has an answer here: Writing and reading (fwrite - fread) structures with pointers 3 answers gcc (GCC) 4.7.0 c89 Hello, I have the following structure that I am trying to fwrite and fread. However, because my device and resource are pointers. The fwrite will read the pointer values and not the data. I cannot use a array for the device or resource. Only pointers as they have to be dynamically allocated. I allocate all memory for the structure elements before I write. Not shown here as I want to keep the snippet short. Nor is free'ing. In my fread function, I allocate the

Javascript examples found on severial sites regardinf fopen is not working for me

回眸只為那壹抹淺笑 提交于 2019-12-02 09:52:39
I am trying to read a text file that is in the same directory as my html file using javascript so that I might include the contents of the text file in my html file. Here is the code I have to test the fopen and fread functions <html> <head> </head> <body> <script> fh = fopen('my.txt', 0); // Open the file for reading. if(fh!=-1) // Check if the file has been successfully opened. { length = flength(fh); // Get the length of the file. str = fread(fh, length); // Read in the entire file. fclose(fh); // Close the file. // Display the contents of the file. write(str); } </script> </body> </html> I

std::vector resize vs reserve during fread

房东的猫 提交于 2019-12-02 08:42:58
This is my working code: size_t FileReader::Read(ByteVector& output) { output.resize(m_elementSize * m_blockSize); size_t read = fread(&output[0], m_elementSize, m_blockSize, m_file); output.resize(read); return read; } However previous I have tried code which had output.reserve(m_elementSize * m_blockSize); As far as I know reserve just founds place in memory for container. resize do the same, also changes memory from trash to some given values and change container size. fread first parameter is void * and it is the same as unsigned char * , my question, why did I get exception while calling

Whats wrong with fread in this program?

走远了吗. 提交于 2019-12-02 08:03:40
I'm intermediate student of C. I'm trying to make a bank management program but first I need to make a login program, so I created one of the following. As I've recently learned about file I/O in C and don't know much about fread and fwrite. I have a file (data.txt) which format if as following. user1 1124 user2 3215 user3 5431 In the following program I've asked user to input user name and pin(4-digit password) and copy file data into a structure then compare these two for verifying information. What is wrong with my program and how to make fread work properly. And is the formating in data

ftell error after the first call to fread

对着背影说爱祢 提交于 2019-12-02 07:14:06
So I have a very simple program that reads the 3 first bytes of a file: int main(void) { FILE *fd = NULL; int i; unsigned char test = 0; fd = fopen("test.bmp", "r"); printf("position: %ld\n", ftell(fd)); for (i=0; i<3; i++) { fread(&test, sizeof (unsigned char), 1, fd); printf("position: %ld char:%X\n", ftell(fd), test); } return (0); } When I try it with a text file it works fine: position: 0 position: 1 char: 61 position: 2 char: 62 position: 3 char: 63 but when I run it with a PNG for example I get: position: 0 position: 147 char:89 position: 148 char:50 position: 149 char:4E Note that the

Reading files with PHP - fopen/fread

与世无争的帅哥 提交于 2019-12-02 07:04:37
问题 <?php $top = "../top.txt"; $middle = "../middle.txt"; $bottom = "../bottom.txt"; $end = "/st.txt"; $data = "/dt.txt"; $handle1 = fopen($top, "r"); $contents1 = fread($handle1, filesize($top)); fclose($handle1); $handle2 = fopen($end, "r"); $contents2 = fread($handle2, filesize($end)); fclose($handle2); $handle3 = fopen($middle, "r"); $contents3 = fread($handle3, filesize($middle)); fclose($handle3); $handle4 = fopen($data, "r"); $contents4 = fread($handle4, filesize($data)); fclose($handle4);

Read Persian (Unicode chars) text file using php

两盒软妹~` 提交于 2019-12-02 03:52:58
问题 I am reading one Persian text file (using PHP) with the help of below code: /* Reading the file name and the book (UTF-8) */ if(file_exists($SourceDirectoryFile)) { $NameBook = "name.txt"; $AboutBook = "about.txt"; $myFile = "Computer-Technolgy/2 ($i)/".$NameBook; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); echo 'Name file: '. $theData.'<hr/>'; } name.txt file contents : آموزش شبكه هاي کامپيوتري (LEARNING NETWORK) Name file: ����� ���� ��� ���������