getwd()
## [1] "/cloud/project"
c(1, 2, 3, 4, 5)
## [1] 1 2 3 4 5
c(1, 2, 3, 4, 5)*2
## [1] 2 4 6 8 10
Y <- c(1, 2, 3, 4, 5)
Y*2 -> Z
Y[1]
## [1] 1
str <- c ("a", "ab", "abc")
length(str)
## [1] 3
nchar(str)
## [1] 1 2 3
一行ずつ読み込んで、リストに格納
txt<-readLines("shiny.txt")
## [1] "Shiny is an R package that makes it easy to build interactive web apps straight from R. "
## [2] "You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. "
## [3] "You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions."
txt[1]
## [1] "Shiny is an R package that makes it easy to build interactive web apps straight from R. "
length(txt)
## [1] 3
Punctuation characters:
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~.
wordLst<-strsplit(txt,"[[:space:]]|[[:punct:]]")
wordLst
## [[1]]
## [1] "Shiny" "is" "an" "R" "package"
## [6] "that" "makes" "it" "easy" "to"
## [11] "build" "interactive" "web" "apps" "straight"
## [16] "from" "R" ""
##
## [[2]]
## [1] "You" "can" "host" "standalone" "apps"
## [6] "on" "a" "webpage" "or" "embed"
## [11] "them" "in" "R" "Markdown" "documents"
## [16] "or" "build" "dashboards" ""
##
## [[3]]
## [1] "You" "can" "also" "extend" "your"
## [6] "Shiny" "apps" "with" "CSS" "themes"
## [11] "" "htmlwidgets" "" "and" "JavaScript"
## [16] "actions"
wordLst<-unlist(wordLst)
## [1] "Shiny" "is" "an" "R" "package"
## [6] "that" "makes" "it" "easy" "to"
## [11] "build" "interactive" "web" "apps" "straight"
## [16] "from" "R" "" "You" "can"
## [21] "host" "standalone" "apps" "on" "a"
## [26] "webpage" "or" "embed" "them" "in"
## [31] "R" "Markdown" "documents" "or" "build"
## [36] "dashboards" "" "You" "can" "also"
## [41] "extend" "your" "Shiny" "apps" "with"
## [46] "CSS" "themes" "" "htmlwidgets" ""
## [51] "and" "JavaScript" "actions"
wordLst<-tolower(wordLst)
## [1] "shiny" "is" "an" "r" "package"
## [6] "that" "makes" "it" "easy" "to"
## [11] "build" "interactive" "web" "apps" "straight"
## [16] "from" "r" "" "you" "can"
## [21] "host" "standalone" "apps" "on" "a"
## [26] "webpage" "or" "embed" "them" "in"
## [31] "r" "markdown" "documents" "or" "build"
## [36] "dashboards" "" "you" "can" "also"
## [41] "extend" "your" "shiny" "apps" "with"
## [46] "css" "themes" "" "htmlwidgets" ""
## [51] "and" "javascript" "actions"
#wordLst<-wordLst[nchar(wordLst)>0]
wordLst<- wordLst[wordLst != ""]
## [1] "shiny" "is" "an" "r" "package"
## [6] "that" "makes" "it" "easy" "to"
## [11] "build" "interactive" "web" "apps" "straight"
## [16] "from" "r" "you" "can" "host"
## [21] "standalone" "apps" "on" "a" "webpage"
## [26] "or" "embed" "them" "in" "r"
## [31] "markdown" "documents" "or" "build" "dashboards"
## [36] "you" "can" "also" "extend" "your"
## [41] "shiny" "apps" "with" "css" "themes"
## [46] "htmlwidgets" "and" "javascript" "actions"
tokens <- length(wordLst)
## [1] 49
types <- length(unique(wordLst))
## [1] 40
\[TTR=\frac{types}{tokens} \times 100 \]
types/tokens*100
## [1] 81.63265
TTR <- round(types/tokens*100,2)
## [1] 81.63
freq<-sort(table(wordLst), decreasing=TRUE)
## wordLst
## apps r build can or shiny
## 3 3 2 2 2 2
## you a actions also an and
## 2 1 1 1 1 1
## css dashboards documents easy embed extend
## 1 1 1 1 1 1
## from host htmlwidgets in interactive is
## 1 1 1 1 1 1
## it javascript makes markdown on package
## 1 1 1 1 1 1
## standalone straight that them themes to
## 1 1 1 1 1 1
## web webpage with your
## 1 1 1 1
全体を1としたときの出現率
relative <- freq / sum(freq)
## wordLst
## apps r build can or shiny
## 0.06122449 0.06122449 0.04081633 0.04081633 0.04081633 0.04081633
## you a actions also an and
## 0.04081633 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816
## css dashboards documents easy embed extend
## 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816
## from host htmlwidgets in interactive is
## 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816
## it javascript makes markdown on package
## 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816
## standalone straight that them themes to
## 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816
## web webpage with your
## 0.02040816 0.02040816 0.02040816 0.02040816
relative
## wordLst
## apps r build can or shiny
## 0.061 0.061 0.041 0.041 0.041 0.041
## you a actions also an and
## 0.041 0.020 0.020 0.020 0.020 0.020
## css dashboards documents easy embed extend
## 0.020 0.020 0.020 0.020 0.020 0.020
## from host htmlwidgets in interactive is
## 0.020 0.020 0.020 0.020 0.020 0.020
## it javascript makes markdown on package
## 0.020 0.020 0.020 0.020 0.020 0.020
## standalone straight that them themes to
## 0.020 0.020 0.020 0.020 0.020 0.020
## web webpage with your
## 0.020 0.020 0.020 0.020
write.csv(freq, "freq_shiny.csv")
barplot(freq, las=3)
colors = c("red", "blue", "green")
barplot(freq, las=3,col=colors)
arg <- 4
sqrt <- sqrt(arg)
paste("平方根は",sqrt)
## [1] "平方根は 2"
printSQRT<- function(arg) {
value <- sqrt(arg)
msg = paste(arg, "の平方根は: ")
paste(msg,value)
}
printSQRT(7)
## [1] "7 の平方根は: 2.64575131106459"
printSQRTr<- function(arg) {
value <- sqrt(arg)
msg = paste(arg, "の平方根は: ")
print(paste(msg,value))
return(sqrt)
}
a<-printSQRTr(7)
## [1] "7 の平方根は: 2.64575131106459"
a
## [1] 2
2^4
## [1] 16
calcPower<- function(arg1, arg2) {
power <- arg1^arg2
return (power)
}
calcPower(2,5)
## [1] 32
\[RTTR=\frac{types}{\sqrt{tokens}} \]
plot(0,0,pch=8)
plot(0,0,pch=8,cex=5)
plot(0,0,pch=8,cex=5,col="red")