The Art of R Programming
It’s a little better to usecat()instead ofprint(), as the latter can print only one expression and its output is numbered, which ...
10.2.1 Reading a Data Frame or Matrix from a File....................... In Section 5.1.2, we discussed the use of the functionr ...
10.2.2 Reading Text Files.............................................. In computer literature, there is often a distinction mad ...
> readLines(c,n=1) character(0) We opened the connection, assigned the result toc, and then read the file one line at a time, ...
10.2.4 Extended Example: Reading PUMS Census Files................... The U.S. Census Bureau makes census data available in the ...
We’ll create a function calledextractpums()to read in a PUMS file and create a data frame from its Person records. The user spec ...
15 # how many Person records? 16 npr <- intextract(hrec,c(106,107)) 17 if (npr > 0) 18 for (i in 1:npr) { 19 prec <- re ...
if (npr > 0) for (i in 1:npr) { ... } } This loop iterates until the end of the input file is reached. The latter condition w ...
Theintextract()function itself is a straightforward conversion of charac- ters to numbers, such as converting the string"12"to t ...
The functionwrite.table()works very much likeread.table(), except that it writes a data frame instead of reading one. For instan ...
You can also usewriteLines(), the counterpart ofreadLines(). If you use a connection, you must specify"w"to indicate you are wri ...
contains the filesfileaandfileb, as well as a subdirectorydir2, which holds the filefilec. The contents of the files are as foll ...
10.3.1 Overview of TCP/IP............................................. TCP/IP is quite complex, so the overview here will be som ...
another of 20 characters. From A’s point of view, that’s two lines, but to TCP/IP, it’s just 28 characters of a yet incomplete m ...
and in myRdsmpackage (both available on CRAN, R’s code repository; see this book’s appendix for details), as follows: •Insnow, t ...
9 con <- cons[[rdy[j]]] 10 # read client request 11 req <- unserialize(con) Againserialize()andunserialize()are good enoug ...
11 STRING MANIPULATION Although R is a statistical language with numeric vectors and matrices playing a central role, character ...
11.1.1 grep()......................................................... The callgrep(pattern,x)searches for a specified substring ...
As you can see, the optional argumentsepcan be used to put something other than a space between the pieces being spliced togethe ...
This reports that “uat” did indeed appear in “Equator,” starting at char- acter position 3. 11.1.8 gregexpr()................... ...
«
9
10
11
12
13
14
15
16
17
18
»
Free download pdf