shinyUI(pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
sliderInput("obs", "Number of observations:",
min = 0, max = 1000, value = 500),
actionButton("goButton", "Go!")
),
mainPanel(
plotOutput("distPlot")
)
))
http://www.r-tutor.com/r-introduction/data-frame
require(graphics)
pairs(mtcars, main = "mtcars data")
coplot(mpg ~ disp | as.factor(cyl), data = mtcars,
panel = panel.smooth, rows = 1)
> mtcars[1:3, ]
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
> mtcars[1,2]
[1] 6
> mtcars["Datsun 710", "cyl"]
[1] 4
> mtcars["Ferrari Dino"]
Error in `[.data.frame`(mtcars, "Ferrari Dino") :
undefined columns selected
> mtcars["Ferrari Dino",]
mpg cyl disp hp drat wt qsec vs am gear carb
Ferrari Dino 19.7 6 145 175 3.62 2.77 15.5 0 1 5 6
> mtcars[("Ferrari Dino", "Datsun 710"),]
Error: unexpected ',' in "mtcars[("Ferrari Dino","
> mtcars[c("Ferrari Dino", "Datsun 710"),]
mpg cyl disp hp drat wt qsec vs am gear carb
Ferrari Dino 19.7 6 145 175 3.62 2.77 15.50 0 1 5 6
Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
> c(nrow(mtcars), ncol(mtcars))
[1] 32 11
> help(mtcars)
> require(graphics)
> pairs(mtcars, main = "mtcars data")
> coplot(mpg ~ disp | as.factor(cyl), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ hp | as.factor(cyl), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ disp | as.factor(cyl), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ disp | as.factor(gear), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ disp | as.factor(qsec), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ cyl | as.factor(qsec), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ disp | as.factor(am), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ wt | as.factor(), data=mtcars, panel=panel.smooth, rows=1)
Error in is.factor(x) : argument "x" is missing, with no default
> coplot(mpg ~ wt | as.factor(mpg), data=mtcars, panel=panel.smooth, rows=1)
> coplot(mpg ~ wt | as.factor(cyl), data=mtcars, panel=panel.smooth, rows=1)
> # mpg ~ wt 의 관계를 cyl 값 별로 그려 보여줌
> # as.factor의 값은 distinct 값이 현저히 낮은 경우 3 ~ 5 개정도가 적당할 듯
> savehistory("D:/jacob/R_working_dir/20140129_script.Rhistory")
> head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
> head(USArrests)
Murder Assault UrbanPop Rape
Alabama 13.2 236 58 21.2
Alaska 10.0 263 48 44.5
Arizona 8.1 294 80 31.0
Arkansas 8.8 190 50 19.5
California 9.0 276 91 40.6
Colorado 7.9 204 78 38.7
> head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
> mtcars[[6]]
[1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440 4.070 3.730 3.780 5.250
[16] 5.424 5.345 2.200 1.615 1.835 2.465 3.520 3.435 3.840 3.845 1.935 2.140 1.513 3.170 2.770
[31] 3.570 2.780
> mtcars[["wt"]]
[1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440 4.070 3.730 3.780 5.250
[16] 5.424 5.345 2.200 1.615 1.835 2.465 3.520 3.435 3.840 3.845 1.935 2.140 1.513 3.170 2.770
[31] 3.570 2.780
> mtcars$wt
[1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440 4.070 3.730 3.780 5.250
[16] 5.424 5.345 2.200 1.615 1.835 2.465 3.520 3.435 3.840 3.845 1.935 2.140 1.513 3.170 2.770
[31] 3.570 2.780
> mtcars[,"am"]
[1] 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1
Logical Operators
Description
These operators act on raw, logical and number-like vectors.
Usage
! x
x & y
x && y
x | y
x || y
xor(x, y)
isTRUE(x)
> mtcars[ (mtcars$wt >= 3 & mtcars$wt <5) & mtcars$mpg > 18 , ]
mpg cyl disp hp drat wt qsec vs am gear carb
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
'Data Analytics' 카테고리의 다른 글
plot( cars, main ="", xlab="", ylab="", type="n") (0) | 2014.01.30 |
---|---|
http://www.r-tutor.com/ (0) | 2014.01.29 |
R practice script 20140128 (0) | 2014.01.29 |
비쥬얼라이제이션 스터디 (0) | 2014.01.28 |
matrix in R (0) | 2014.01.27 |