.


:




:

































 

 

 

 





2

- . , .

 

R

- R. , , R , , . : , .

. , , - , (Emacs/Vi ). , , , , . - , , . (, ), .

- , R , . R :

> getwd()

[1] "/home/username/"__

, . :

> setwd("./workdir") > getwd() [1] "/home/username/workdir"

, - help(getwd). , - :

> dir() [1] "mydata.txt"

. read.table():

> read.table("mydata.txt", sep=";", head=TRUE)

1 1 2 3 2 4 5 6 3 7 8 9

"mydata.txt", C:\Users\student\Documents , :

 

1;2;2

123;1222;22244

123;322;1122

4555;1566;1145

 

read.table("mydata.txt", sep=";", head=TRUE)

 

, ";" (.. head=TRUE). mydata-unicode.txt, .

, . , (head=TRUE) (sep=";"). read.table() , , . R,

file.show():

> file.show("mydata.txt")

;; 1;2;3 4;5;6 7;8;9

R , read.table(), . , sep "". , , , sep . , , , . , , :

1) , :

> read.table("../workdir/mydata.txt")

2) , . ru_RU.UTF-8, KOI8-R, file():

> read.table("mydata.txt", sep=";", head=TRUE,encoding="KOI8-R")

1 1 2 3 2 4 5 6 3 7 8 9

3) , R . , ( ):

> file.show("mydata2.txt")

1 2 3 4 5 6 7 8 9

> read.table("mydata2.txt", head=TRUE)

1 2 3 4 5 6 7 8 9

4) , . - , dec:

> read.table("mydata3.txt", dec=",", h=T)

1.1 2.2 3.3 4.4 5.0 6.0 7.0 8.0 9.0

(h=T). , , TRUE/FALSE.

, . , ,

R, - ( Perl). . , , , , , MS Excel. , : R? : , . , . , . R .

R foreign, - , Minitab, S, SAS, SPSS, Stata, Systat, DBF. , :

> library(foreign)

> help(package=foreign)

Excel, . , R , . MS Excel 2007 . R . OpenOffice Calc xls-, , R:

> read.table("clipboard")

, .

, , Excel- . : - . , / , . :

R!

:

R . . pixmap. R ArcInfo . ( maps, maptools) .

2) R . , .

> x <- ""

> save(x, file="x.rd")

> rm(x)

> x

: "x"

> dir()

[1] "x.rd"

> load("x.rd")

> x

[1] ""

save() load(), <-, rm().

3) R , , MySQL, PostgresSQL SQLite ( R, . RSQLite sqldf).

4) , R , , , . .

 

, , R , .

R . , lattice, , , CRAN. , R . , .

X- ( ) , :

> X11(fonts = c(+ "-rfx-helvetica-%s-%s-*-*-%d-*-*-*-*-*-koi8-r",+ "-adobe-symbol-medium-r-*-*-%d-*-*-*-*-*-*-*"))

. 2.1. X11

fonts X11 , c(). , , , , . xfontsel . Fonts , help(X11). :

> plot(1:20, main="")

> legend("topleft", pch=1, legend="␣")

, . , , . , R. : plot() , ( generic, ). , , , . , 1:20 1 20, , , ( ), .

- , , , . :

> plot(cars)

> title(main="␣20-␣")

, . , plot(), , title(). cars1 R , , . , , : speed distance ( ). plot() , , scatterplot, X (), Y , . , plot(), , , trees. , , , data() ( , ).

 

plot(), R , , 2 . , , R . :

> dev.off()

R , , , , . R , ( Mac OS X ). , . . ( - ), . :

> png(file="1-20.png", bg="transparent")

> plot(1:20)

> dev.off()

png() , , (, , Web). . - dev.off(), 1-20.png. png() . , , . jpeg(), - jpeg-.

R , , PDF. , , . . PDF-, :

> pdf("1-20.pdf",family="NimbusSan",encoding="KOI8-R.enc")

> plot(1:20, main="")

> dev.off()

> embedFonts("1-20.pdf")

, , , , . , R: CP1251.enc KOI8-U.enc. embedFonts(). , NimbusSan R Ghostscript, , . PDF, R , , PostScript, xfig picTeX. RSvgDevice, SVG. , , Inkscape.

 

, R . , R. , , : . , , , :

> # eps- 6 6

> postscript("2hist.eps",width=6.0,height=6.0, + horizontal=FALSE,onefile=FALSE,paper="special")

> #

> old.par <- par(mfrow=c(2,1))

> hist(cars$speed)

> hist(cars$dist) > #

> par(old.par)

> dev.off()

par() , mfrow, . mfrow c(1,1), . par() ( 71 ), old.par, . , hist() , .

 

. 2.2.





:


: 2016-04-03; !; : 346 |


:

:

: , .
==> ...

1649 - | 1619 -


© 2015-2024 lektsii.org - -

: 0.03 .