Professional Documents
Culture Documents
R Version 3
R Version 3
> 2+2
[1] 4
>x
Error: objeto 'x' no encontrado
> x<-2
>x
[1] 2
> x+x
[1] 4
> y<-x+x
>y
[1] 4
> peso<-c(60,70,80,90,100)
> peso
[1] 60 70 80 90 100
> Enorm(15)
Error: no se pudo encontrar la funcin "Enorm"
> Ernorm(15)
Error: no se pudo encontrar la funcin "Ernorm"
> Enorm(15)
Error: no se pudo encontrar la funcin "Enorm"
> rnorm(15)
[1] -0.09156132 0.27116751 1.14782468 -0.93962827 1.82457948
-0.67277553
[7] 0.59714 248 -1.28884141 2.40275865 -0.25590020 -0.47069998
-0.08833632
[13] 0.66677849 0.51115291 -1.96689498
> al<-rnorm(15)
> al
[1] 0.22074328 -2.03384002 1.48783896 0.87069384 2.84172017
-0.73843798
[7] 1.11238844 -0.09468982 -0.54074205 1.82273762 1.60791268
1.20035212
[13] -0.25661125 0.71722739 -0.95860322
> al[13]
[1] -0.2566113
> mean(al)
[1] 0.4839127
> max(al)
[1] 2.84172
> min(al)
[1] -2.03384
> sum(al)
[1] 7.25869
> al[al>0]
[1] 0.2207433 1.4878390 0.8706938 2.8417202 1.1123884 1.8227376
1.6079127
[8] 1.2003521 0.7172274
> max(peso)
[1] 100
> demo()
> demo(graphica)
Error in demo(graphica) : No demo found for topic graphica
> demo(graphics)
demo(graphics)
---- ~~~~~~~~
> ## Here is some code which illustrates some of the differences between
> ## R and S graphics capabilities. Note that colors are generally specified
> ## by a character string name (taken from the X11 rgb.txt file) and that line
> ## textures are given similarly. The parameter "bg" sets the background
> ## parameter for the plot and there is also an "fg" parameter which sets
> ## the foreground color.
>
>
> x <- stats::rnorm(50)
> ## probably find that numerically equispaced does not mean visually
> ## equispaced. On my display at home, these colors tend to cluster at
> ## the RGB primaries. On the other hand on the SGI Indy at work the
> ## effect is near perfect.
>
> par(bg = "gray")
> ## We have already confessed to having these. This is just showing off X11
> ## color names (and the example (from the postscript manual) is pretty
"cute".
>
> pie.sales <- c(0.12, 0.3, 0.26, 0.16, 0.04, 0.12)
> pie(pie.sales,
+
col = c("purple","violetred1","green3","cornsilk","cyan","white"))
> title(xlab = "(Don't try this at home kids)", cex.lab = 0.8, font.lab = 3)
> ## Boxplots: I couldn't resist the capability for filling the "box".
> ## The use of color seems like a useful addition, it focuses attention
> ## on the central bulk of the data.
>
> par(bg="cornsilk")
> n <- 10
You do need to be
> ## over the top and you can end up with your lunch all over the keyboard.
> ## On the other hand, my market research clients love it.
>
> x <- c(0.00, 0.40, 0.86, 0.85, 0.69, 0.48, 0.54, 1.09, 1.11, 1.73, 2.05, 2.02)
> par(bg="lightgray")
> box()
> ## A filled histogram, showing how to change the font used for the
> ## main title without changing the other annotation.
>
> par(bg="cornsilk")
> box()
> par(opar)
>
> demo(colors)
demo(colors)
---- ~~~~~~
>
> ## 1) with traditional 'graphics' package:
> showCols1 <- function(bg = "gray", cex = 0.75, srt = 30) {
+
##
require("graphics")
+}
> showCols1()
Esperando para confirmar cambio de pgina...
##
require("grid")
grid.rect(gp=gpar(fill=bg))
+}
> showCols2()
Loading required package: grid
Esperando para confirmar cambio de pgina...
> ###
>
> ##' @title Comparing Colors
> ##' @param col
> ##' @param nrow
> ##' @param ncol
> ##' @param txt.col
> ##' @return the grid layout, invisibly
> ##' @author Marius Hofert, originally
> plotCol <- function(col, nrow=1, ncol=ceiling(length(col) / nrow),
+
txt.col="black") {
require(grid)
grid.newpage()
pushViewport(viewport(layout=gl))
ic <- 1
for(i in 1:nrow) {
for(j in 1:ncol) {
pushViewport(viewport(layout.pos.row=i, layout.pos.col=j))
grid.rect(gp= gpar(fill=col[ic]))
grid.text(col[ic], gp=gpar(col=txt.col))
upViewport()
ic <- ic+1
upViewport()
invisible(gl)
+}
nrow=2)
> ##' Find close R colors() to a given color {original by Marius Hofert)
> ##' using Euclidean norm in (HSV / RGB / ...) color space
> nearRcolor <- function(rgb, cSpace = c("hsv", "rgb255", "Luv", "Lab"),
+
+{
+
"rgb255" = identity,
"hsv" = rgb2hsv,
+}
21.1
25.8
29.5
"tan1" "sandybrown"
"sienna1"
0.0410
0.0618
0.0638
"sienna2"
"coral2"
"tomato2"
0.0900
0.0912
0.0918
"sienna1" "sandybrown"
"coral1"
0.0667
0.0766
"tan1"
"tomato"
7.42
7.48
12.41
"tan1" "sandybrown"
13.69
"orange3"
5.56
8.08
11.31
"tan1" "sandybrown"
> nearRcolor("#334455")
0.0867
"darkslategray"
"peru"
"orange2"
"coral"
> install.packages("gstat")
Warning in install.packages("gstat") :
'lib = "C:/Program Files/R/R-3.2.1/library"' is not writable
--- Please select a CRAN mirror for use in this session --also installing the dependencies xts, intervals, sp, zoo, spacetime, FNN
probando la URL
'http://cran.revolutionanalytics.com/bin/windows/contrib/3.2/xts_0.9-7.zip'
Content type 'application/zip' length 662241 bytes (646 KB)
downloaded 646 KB
probando la URL
'http://cran.revolutionanalytics.com/bin/windows/contrib/3.2/intervals_0.15.0.zi
p'
Content type 'application/zip' length 653727 bytes (638 KB)
downloaded 638 KB
probando la URL
'http://cran.revolutionanalytics.com/bin/windows/contrib/3.2/sp_1.1-1.zip'
Content type 'application/zip' length 1519801 bytes (1.4 MB)
downloaded 1.4 MB
probando la URL
'http://cran.revolutionanalytics.com/bin/windows/contrib/3.2/zoo_1.7-12.zip'
Content type 'application/zip' length 897258 bytes (876 KB)
downloaded 876 KB
probando la URL
'http://cran.revolutionanalytics.com/bin/windows/contrib/3.2/spacetime_1.14.zip'
Content type 'application/zip' length 2980087 bytes (2.8 MB)
downloaded 2.8 MB
probando la URL
'http://cran.revolutionanalytics.com/bin/windows/contrib/3.2/FNN_1.1.zip'
Content type 'application/zip' length 532847 bytes (520 KB)
downloaded 520 KB
probando la URL
'http://cran.revolutionanalytics.com/bin/windows/contrib/3.2/gstat_1.0-25.zip'
Content type 'application/zip' length 2784947 bytes (2.7 MB)
downloaded 2.7 MB
>
> demo(gstat)
Error in demo(gstat) : No demo found for topic gstat
> demo(gstat)
Error in demo(gstat) : No demo found for topic gstat
> library (gstat)
Warning message:
package gstat was built under R version 3.2.2
> demo()
> demo(examples)
demo(examples)
---- ~~~~~~~~
> data(meuse)
> coordinates(meuse)=~x+y
> ##
> ## ex03.cmd:
> ## Inverse distance interpolation on a mask map
> ##
> data(meuse.grid)
> library(lattice)
> spplot(x[1])
Esperando para confirmar cambio de pgina...
> ##
> ## ex04.cmd
> ## Local ordinary block kriging at non-gridded locations
> ##
> ## the gstat "classic" radius maps into the gstat "S" maxdist argument
> ##
> new.locs <- SpatialPoints(cbind(x = c(181170, 180310, 180205, 178673,
178770, 178270),
+
maxdist = 1000)
> ##
> ## ex05.cmd
> ##
> ## Local simple point kriging on a mask map
> ##
> v <- vgm(0.581, "Sph", 900, nug = 0.0554)
> ##
> ## ex06.cmd
> ##
> ## Unconditional Gaussian simulation on a mask
> ## (local neigbourhoods, simple kriging)
> ##
> x <- krige(log(zinc) ~ 1, locations = NULL, newdata = meuse.grid,
+
> ##
> ## ex07.cmd
> ##
> ## Gaussian simulation, conditional upon data
> ## (local neighbourhoods, simple and ordinary kriging)
> ##
> x <- krige(log(zinc) ~ 1, meuse, meuse.grid,
+
> ##
> ## ex08.cmd
> ##
> ## Change of support: local ordinary block kriging on a mask
> ##
> x <- krige(log(zinc) ~ 1, meuse, meuse.grid,
+
block = c(40,40))
> ##
> ## ex09.cmd
> ##
> ## Obtain map values at data() locations
> ## (Point-map overlay)
> ##
> # we trick here by using inv.weighted distance interpolation, using the
> # single nearest observation. It will not fail on points outside the grid.
> # Note that we reversed meuse.grid and meuse to get these results.
> x <- krige(part.a ~ 1, meuse.grid, meuse, model = NULL, nmax = 1)
[inverse distance weighted interpolation]
> ##
> ## ex10.cmd
> ##
> ## Multiple kriging: prediction on more than one variable
> ## (ordinary kriging of two variables)
> ## (note that zinc_map.eas wass obtained through ex09.gst)
> ##
> x <- variogram(dist~1,meuse)
> ##
> ## ex11.cmd
> ##
> ## Multivariable kriging: ordinary local cokriging of two variables
> ## For examples of fitting an LMC: see demo(cokriging)
> ##
> g <- gstat(id = "ln.zinc", form = log(zinc) ~ 1,
+
> ##
> ## ex12.cmd
> ##
> ## Stratified ordinary kriging (within-category ordinary kriging)
> ##
>
> # find out in which part the data are:
> meuse$part.a = krige(part.a~1, meuse.grid, meuse, nmax=1)$var1.pred
[inverse distance weighted interpolation]
> ##
> ## ex13.cmd
> ##
> ## Local universal kriging, using one continuous variable
> ###
> ## the variogram should be that of the residual:
> x <- krige(log(zinc) ~ sqrt(dist), meuse, meuse.grid,
+
> ##
> ## ex14.cmd
> ##
> ## Universal kriging, using one continuous and
> ## two binary variables.
> ##
> x <- krige(log(zinc) ~ -1 + sqrt(dist)+ part.a + part.b,
+
> spplot(meuse.grid["part.a"], main = "the areas defining part.a (1) and part.b
(0)")
Esperando para confirmar cambio de pgina...
> ##
> ## ex14a.cmd
> ##
> ## stratified universal kriging:
> ## (again: not implemented)
> ##
>
> ## ex15.cmd
> ##
> ## Local linear model, using one continuous variable
> ##
> x <- krige(log(zinc) ~ sqrt(dist), meuse, meuse.grid,
+
> ##
> ## ex16.cmd
> ##
> ## Multivariable indicator cosimulation
> ## ==>> see demo(cosimulation) for an extended example how to do this
> ##
>
> ##
> ## ex17.cmd
> ##
> ## global coordinate polynomial trend surfaces
> ## trend orders 0-3 ==>> better use lm() for this
> ##
Warning message:
package sp was built under R version 3.2.2
> x<-c(1,2,3,4,5,6,7,8,9,10)
> x$
+
+
+
+
+c
Error in x$c : $ operator is invalid for atomic vectors
> x^2
[1] 1 4 9 16 25 36 49 64 81 100
> x<-seq(0,4,0.1)
>x
[1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8
[20] 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7
[39] 3.8 3.9 4.0
> mean(x)
[1] 2
> plot(x,x^2,type="l")
> plot(x,x^2,type="p")
> plot(x,x^2,type="l"
+c
Error: unexpected symbol in:
"plot(x,x^2,type="l"
c"
> plot(x,x^2,type="l")
> plot(x,x^2)
> plot(x,x^2,type="l",col="blue")
> x=rnom(30)
Error: no se pudo encontrar la funcin "rnom"
> x=rnorm (30)
> p<-rnorm (30)
>p
[1] -0.891861978 -0.122828218 0.877440176 1.267248900 0.627286959
[6] -0.378100966 0.858271393 0.303717256 -0.565343522 -1.928233269
[11] 0.746375452 -0.206070941 -0.010140040 -0.473720599 -2.022354366
[16] 0.216574821 -0.601776872 0.002840592 -0.442315720 -1.672318091
[21] -1.050505918 0.375925133 -0.394971374 0.281650376 -1.589366158
[26] 0.182030517 1.888707124 2.660406643 -0.911409240 -0.576548984
> plot(x,x^2,type="l",col="blue")
> hist(p)
> e<-rnorm(30)
> plot(p)
> plot(e,p,type="l")
> p+e
[1] -0.85103940 1.40573141 1.11172503 0.54711536 0.81270268
-0.66928198
[7] 0.84658020 0.46128848 0.53052053 -1.79054859 0.83191301
-0.90060065
[13] 0.63033389 -1.63290437 -1.10382111 1.87431871 0.46317276
0.65025830
[19] -0.20072392 -1.43168431 -0.63078173 0.00272631 -1.32219185
-0.13892253
[25] -2.53684916 -0.59669804 0.66247343 3.19140369 -0.71840342
-0.49216694
> a=p,e
Error: inesperado ',' in "a=p,"
> r<-(p,e)
Error: inesperado ',' in "r<-(p,"
> p,e