Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
git clone https://github.com/wacode5/R2
GitHub Download
exercise.R
R &














CRAN






1
is(1)
2.1
is(2.1)
1 + 1
3 - 1
6 * 2
4 / 2
2^5
log10(5)


"WACODE"
is("WACODE")
is(1)
is("1")
try(1 + "1")
paste0("WACODE...
TRUE
is(TRUE)
FALSE
is(FALSE)
1 == 1
1 == 2
"python" == "python"
"python" == "R"
"python" != "R"
hoge <- read.table(“hoge.txt”, stringsAsFactor=FALSE)
WACODE <- factor(
c("python", “python",
"R", "R", “R",
"julia", "jul...
as.numeric(“12345”)
as.character(WACODE)
as.numeric(WACODE)
✖


is(1)
A <- c(2, 3, 1)
B <- c(-2, 1, -2)
A[1]
A[2]
A[3]
A[4]
max(A)
min(A)
mean(B)
median(B)
A * B
A %*% B
C <- c("A", "B",...
E <- matrix(runif(6), nrow=2, ncol=3)
E[1,]
E[,2]
nrow(E)
ncol(E)
dim(E)
cbind(A, B)
rbind(E, A, B)
rowSums(E)
colSums(E)
...


data(iris)
head(iris)
G <- list(

X = c(1,2,3),
Y = matrix(runif(9), nrow=3),
Z = TRUE)
G$X
G$Y
G$Z
x <- runif(10)
y <- runif(10)
lr <- lm(y ~ x)
str(lr)
lr$coefficients


R <- "R"
julia <- "julia"
if(R == julia){
print("Same!!!")
}else{
print("Different...")
}
H <- 1:20
for(i in 1:length(H)){
print(H[i])
}
j <- 1
while(j <= 20){
print(H[j])
j <- j + 1
}
jijou <- function(x){
if(is.numeric(x)){
x^2
}else{
stop("x is not numeric!!!")
}
}
jijou(3)
try(jijou("3"))


y <- "WACODE"
sapply(1:5, function(x, y){
cat(paste0(y, x, "n"))
}, y=y)
apply(matrix(1:12, nrow=3), 1, mean)
apply(matrix...
(d <- getwd())
setwd("../")
getwd()
setwd(d)
getwd()
write.table(iris, "iris.txt")
iris.tsv <- read.table("iris.txt")
write.csv(iris, "iris.csv")
iris.csv <- read.csv("iris.cs...




name = “Taro”
grade = 4
sex = “Male”
programming = TRUE
name = “Jiro”
grade = 3
sex = “Male”
programming = FALSE
name = ...
taro <- list(name="Taro",grade=4,sex="Male", programming=T)
jiro <- list(name="Jiro",grade=3,sex="Male", programming=F)
ha...
methods(,"Student")
inherits(taro, "Student")
inherits(jiro, "Student")
inherits(hanako, "Student")
show(taro)
show(jiro)
...
setClass("student",
representation(
name="character",
grade="numeric",
sex="character",
programming="logical"
),
prototype...
setGeneric("show",
function(object) {
standardGeneric("show")
}
)
setMethod("show", "student",
function(object){
cat("This...
taro <- new("student",name="Taro", grade=4, sex="Male", programming=T)
jiro <- new("student",name="Jiro", grade=3, sex="Ma...
st <- setRefClass(
Class = "Student",
fields = list(
name = "character",
grade = "numeric",
sex = "character",
programming...
taro <- st$new(name="Taro", grade=4, sex="Male",
programming=TRUE)
jiro <- st$new(name="Jiro", grade=3, sex="Male",
progra...
install.packages("R6")
library("R6")
st <- R6Class("Student",
public = list(
name = "John Doe",
grade = 1,
sex = "Male",
p...
taro <- st$new(name="Taro", grade=4, sex="Male",
programming=TRUE)
jiro <- st$new(name="Jiro", grade=3, sex="Male",
progra...
install.packages("rgl")
library("rgl")
source("https://bioconductor.org/biocLite.R")
biocLite("meshr")
library("meshr")
in...
ls("package:rgl")
?plot3d
demo("rgl")
vignette("rgl")
















package.skeleton(name=“plotWikipedia",
list=c("Word2Vec", “HyperLink”, “label.Pokemon”,
“plotlyGraph", "plotlyScatter"))














H <- 1:20
for(i in 1:length(H)){
print(H[i])
}












































CRAN













 























Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Rによる統計解析と可視化
Upcoming SlideShare
Loading in …5
×

Rによる統計解析と可視化

3,388 views

Published on

WACODE 5th

Published in: Science
  • Be the first to comment

Rによる統計解析と可視化

  1. 1. git clone https://github.com/wacode5/R2 GitHub Download exercise.R R &
  2. 2.
  3. 3. 
 
 
 

  4. 4. 
 
 CRAN
  5. 5.
  6. 6.
  7. 7.
  8. 8. 1 is(1) 2.1 is(2.1) 1 + 1 3 - 1 6 * 2 4 / 2 2^5 log10(5) 
 "WACODE" is("WACODE") is(1) is("1") try(1 + "1") paste0("WACODE", "5") paste0("WACODE", 5)
  9. 9. TRUE is(TRUE) FALSE is(FALSE) 1 == 1 1 == 2 "python" == "python" "python" == "R" "python" != "R"
  10. 10. hoge <- read.table(“hoge.txt”, stringsAsFactor=FALSE) WACODE <- factor( c("python", “python", "R", "R", “R", "julia", "julia", "julia")) nlevels(WACODE) levels(WACODE)
  11. 11. as.numeric(“12345”) as.character(WACODE) as.numeric(WACODE) ✖ 

  12. 12. is(1) A <- c(2, 3, 1) B <- c(-2, 1, -2) A[1] A[2] A[3] A[4] max(A) min(A) mean(B) median(B) A * B A %*% B C <- c("A", "B", "C", "A", "AA") which(C == "A") length(which(C == "A"))
  13. 13. E <- matrix(runif(6), nrow=2, ncol=3) E[1,] E[,2] nrow(E) ncol(E) dim(E) cbind(A, B) rbind(E, A, B) rowSums(E) colSums(E) rowMeans(E) colMeans(E)
  14. 14. 
 data(iris) head(iris) G <- list(
 X = c(1,2,3), Y = matrix(runif(9), nrow=3), Z = TRUE) G$X G$Y G$Z
  15. 15. x <- runif(10) y <- runif(10) lr <- lm(y ~ x) str(lr) lr$coefficients 

  16. 16. R <- "R" julia <- "julia" if(R == julia){ print("Same!!!") }else{ print("Different...") }
  17. 17. H <- 1:20 for(i in 1:length(H)){ print(H[i]) } j <- 1 while(j <= 20){ print(H[j]) j <- j + 1 }
  18. 18. jijou <- function(x){ if(is.numeric(x)){ x^2 }else{ stop("x is not numeric!!!") } } jijou(3) try(jijou("3")) 

  19. 19. y <- "WACODE" sapply(1:5, function(x, y){ cat(paste0(y, x, "n")) }, y=y) apply(matrix(1:12, nrow=3), 1, mean) apply(matrix(1:12, nrow=3), 2, var) sapply(-3:3, abs) lapply(list(A=1:3, B=matrix(1:12, nrow=3)), print)
  20. 20. (d <- getwd()) setwd("../") getwd() setwd(d) getwd()
  21. 21. write.table(iris, "iris.txt") iris.tsv <- read.table("iris.txt") write.csv(iris, "iris.csv") iris.csv <- read.csv("iris.csv") save(iris, file="iris.RData") load("iris.RData") save.image("20160806_WACODE.RData") load("20160806_WACODE.RData" system("ls")
  22. 22.
  23. 23. 
 name = “Taro” grade = 4 sex = “Male” programming = TRUE name = “Jiro” grade = 3 sex = “Male” programming = FALSE name = “Hanako” grade = 1 sex = “Female” programming = TRUE This Student's name is Taro Taro 's grade is 4 Taro 's sex is Male Taro loves programming!!! This Student's name is Taro Taro 's grade is 4 Taro 's sex is Male Taro loves programming!!! This Student's name is Taro Taro 's grade is 4 Taro 's sex is Male Taro loves programming!!! show(hanako) show(jiro) show(taro)
  24. 24. taro <- list(name="Taro",grade=4,sex="Male", programming=T) jiro <- list(name="Jiro",grade=3,sex="Male", programming=F) hanako <- list(name="Hanako",grade=1,sex="Female", programming=T) class(taro) <- "Student" class(jiro) <- "Student" class(hanako) <- "Student" show.Student <- function(object){ cat("This Student's name is",object$name,"n", object$name,"'s grade is",object$grade,"n", object$name,"'s sex is",object$sex,"n") if(object$programming){ cat(object$name,"loves programming!!!n") }else{ cat(object$name,"does not love programming....n") } }
  25. 25. methods(,"Student") inherits(taro, "Student") inherits(jiro, "Student") inherits(hanako, "Student") show(taro) show(jiro) show(hanako)
  26. 26. setClass("student", representation( name="character", grade="numeric", sex="character", programming="logical" ), prototype=prototype( name="John Doe", grade=1, sex="Male", programming=TRUE ), validity=function(object){ (nchar(object@name) >1)&& ((object@grade >= 1)&&(object@grade <= 4))&& ((object@sex=="Male")||(object@sex=="Female"))&& ((object@programming==TRUE)||(object@programming==FALSE)) } )
  27. 27. setGeneric("show", function(object) { standardGeneric("show") } ) setMethod("show", "student", function(object){ cat("This Student's name is",object@name,"n", object@name,"'s grade is",object@grade,"n", object@name,"'s sex is",object@sex,"n") if(object@programming){ cat(object@name,"loves programming!!!n") }else{ cat(object@name,"does not love programming....n") } } )
  28. 28. taro <- new("student",name="Taro", grade=4, sex="Male", programming=T) jiro <- new("student",name="Jiro", grade=3, sex="Male", programming=F) hanako <- new("student",name="Hanako", grade=1, sex="Female", programming=T) inherits(taro, "student") inherits(jiro, "student") inherits(hanako, "student") show(taro) show(jiro) show(hanako) try(kazuo <- new("student",name="Kazuo",grade=5, sex="Male",programming=F))
  29. 29. st <- setRefClass( Class = "Student", fields = list( name = "character", grade = "numeric", sex = "character", programming = "logical" ), methods = list( show = function(){ cat("This Student's name is",name,"n", name,"'s grade is",grade,"n", name,"'s sex is",sex,"n") if(programming){ cat(name,"loves programming!!!n") }else{ cat(name,"does not love programming....n") } } ) )
  30. 30. taro <- st$new(name="Taro", grade=4, sex="Male", programming=TRUE) jiro <- st$new(name="Jiro", grade=3, sex="Male", programming=FALSE) hanako <- st$new(name="Hanako", grade=1, sex="Female", programming=TRUE) inherits(taro,"Student") inherits(jiro,"Student") inherits(hanako,"Student") taro$show() jiro$show() hanako$show()
  31. 31. install.packages("R6") library("R6") st <- R6Class("Student", public = list( name = "John Doe", grade = 1, sex = "Male", programming = TRUE, initialize = function(name, grade, sex, programming){ self$name = name self$grade = grade self$sex = sex self$programming = programming }, show = function(){ cat("This Student's name is", self$name, "n", self$name,"'s grade is", self$grade, "n", self$name,"'s sex is", self$sex, "n") private$bool_program() } ), private = list( bool_program = function(){ if(self$programming){ cat(self$name, "loves programming!!!n") }else{ cat(self$name, "does not love programming....n") } } ) )
  32. 32. taro <- st$new(name="Taro", grade=4, sex="Male", programming=TRUE) jiro <- st$new(name="Jiro", grade=3, sex="Male", programming=FALSE) hanako <- st$new(name="Hanako", grade=1, sex="Female", programming=TRUE) inherits(taro,"Student") inherits(jiro,"Student") inherits(hanako,"Student") taro$show() jiro$show() hanako$show()
  33. 33. install.packages("rgl") library("rgl") source("https://bioconductor.org/biocLite.R") biocLite("meshr") library("meshr") install.packages("devtools") library("devtools") install_github("rikenbit/CCIPCA") library("CCIPCA")
  34. 34. ls("package:rgl") ?plot3d demo("rgl") vignette("rgl")
  35. 35. 
 

  36. 36. 
 
 
 
 

  37. 37.
  38. 38. package.skeleton(name=“plotWikipedia", list=c("Word2Vec", “HyperLink”, “label.Pokemon”, “plotlyGraph", "plotlyScatter")) 

  39. 39.
  40. 40.
  41. 41.
  42. 42. 
 
 

  43. 43. H <- 1:20 for(i in 1:length(H)){ print(H[i]) }
  44. 44.
  45. 45.
  46. 46.
  47. 47. 
 

  48. 48.
  49. 49.
  50. 50.
  51. 51.
  52. 52. 
 

  53. 53. 
 

  54. 54.
  55. 55.
  56. 56. 
 
 
 

  57. 57.
  58. 58.
  59. 59. 
 CRAN 
 

  60. 60. 
 

  61. 61.
  62. 62. 
 
 
 

  63. 63. 
 

  64. 64. 
 

  65. 65. 
 
 

  66. 66. 
 
 


×