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", "5")
paste0("WACODE", 5)
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", "julia", "julia"))
nlevels(WACODE)
levels(WACODE)
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", "C",
"A", "AA")
which(C == "A")
length(which(C == "A"))
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)


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(1:12, nrow=3), 2, var)
sapply(-3:3, abs)
lapply(list(A=1:3, B=matrix(1:12, nrow=3)), print)
(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.csv")
save(iris, file="iris.RData")
load("iris.RData")
save.image("20160806_WACODE.RData")
load("20160806_WACODE.RData"
system("ls")




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)
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")
}
}
methods(,"Student")
inherits(taro, "Student")
inherits(jiro, "Student")
inherits(hanako, "Student")
show(taro)
show(jiro)
show(hanako)
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))
}
)
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")
}
}
)
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))
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")
}
}
)
)
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()
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")
}
}
)
)
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()
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")
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による統計解析と可視化