HOME > > R <

R <

若吾吟吾сS 篋違 R 篏帥<≪ R R 篏帥違R <≪鐚紜茖壕鐚


腟沿純 R 泣障篏帥堺綽с<≪

R CRAN (The Comprehensive R Archive Network) http://cran.r-project.org/ ユсャ≪祉ャ≪pdf 2040 若吾鐚鐚鐚

絖吾с

吾с篁吾с筝障馹

紊荐茯с医ゃ違吾с医ゃ泣吾с絋R 違篁ヤ v s 紊絎違激 1 3 с吾с激馹с鐚篁罕 R 篏帥for 若吾c鐚

> s <- 1
> s
[1] 1
> v <- c(1, 2, 3)
> v
[1] 1 2 3

筝 v 医ゃ冴[ ] 羞糸 0 с 1 紮障

> v[2]
[1] 2

s v 篁吾с障с絖(atomic)吾с泣蕁

> is.atomic(s)
[1] TRUE
> is.atomic(v)
[1] TRUE

絖絖吾с

> c <- "Hello."
> c
[1] "Hello."
> is.atomic(c)
[1] TRUE

鴻吾с激灸ゃ絮фゃ

> mode(s)
[1] "numeric"
> length(s)
[1] 1
> mode(v)
[1] "numeric"
> length(v)
[1] 3
> mode(c)
[1] "character"
> length(c)
[1] 1

null 腥冴logical 純numeric 絎違complex 茲膣違character 絖

с吾с激 1 с篁ヤс馹

> s <- 1
> v <- c(1, 2, 3)
> mode(s)
[1] "numeric"
> mode(v)
[1] "numeric"

c( ) ∽違篏帥筝ゃ吾с障с∞茵違綣桁句紊

> mode(1)
[1] "numeric"
> mode("abc")
[1] "character"
> mode(c(1, "abc")[1])
[1] "character" #  numeric c 1  character 紊

絖吾с鴻泣

∽ list() 鴻篏

> L <- list(1, 2, 3)
> L
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

> is.atomic(L)
[1] FALSE

鴻鴻激荀膣違

> mode(L)
[1] "list"
> length(L)
[1] 3

v 絋鴻鴻

> is.list(L)
[1] TRUE
> is.list(v)
[1] FALSE

鴻荀膣冴 [[ ]]

> L[[2]]
[1] 2

鴻荀膣鴻緇 [ ]

> L[2]
[[1]]
[1] 2

[[ ]] [ ] 阪ャ紊т

> mode(L[[2]])
[1] "numeric"
> mode(L[2])
[1] "list"

鴻違吾с緇

> p <- list(1, "one")
> p
[[1]]
[1] 1

[[2]]
[1] "one"

絮т

吾с激祉篁紙絮с筝吾с

> attr(s, "english")="one"
> attr(s, "english")
[1] "one"

(mode)激(length)(names)篁ュ絮с吾с若吟筝腓鞘х絎臂違c羈綽荀с

絖吾сs <- 1
v <- c(1,2,3)
attr(s, "english") <- "one"
attr(v, "english") <- "one to three"
絖吾сL <- list(1,2,3)attr(L, "english") <- "list of one to three"

鐚mode length names 篁ュ鐚絮с吾ссc(1, 2, 3) с1 障罕сc(1, 2, 3) names 篁ュ絮с篁違с荐

> dog <- c(1, 2, 3)
> is.vector(dog)
[1] TRUE
> cat <- 1
> is.vector(cat)
[1] TRUE
> attr(dog, "japanese") <- "inu"
> is.vector(dog)
[1] FALSE

鴻絲障絮сゃ箴水紊絮с筝鴻荀膣違激絖с蚊ゃ蚊ゃ鴻荀膣絲上

> crayon <- list(0, 5, 29)
> attr(crayon, "names") <- c("himawari", "shinnosuke", "misae")
> crayon[["shinnosuke"]]
[1] 5

attr(x, "names") names(x) ヨс

x[["y"]] x$y ヨс

names 絮сゃс

> a <- c(1, 2, 3)
> names(a) <- c("one", "two", "three")
> a["two"]
two
  2

障障絮сよ吾с絮уャ翫names(attributes(x)) attributes (x) 吾с x 鴻絮с 1 ゃ鴻菴絮с絮ус

羂贋絮

鐚≧吾鐚

茵鐚紊翫激 1 激с鐚激 2 鐚茵違糸逸罨≦絮эdim鐚筝篏

> m<-c(1, 2, 3, 4, 5, 6)
> m
[1] 1 2 3 4 5 6
> attr(m, "dim") <- c(2, 3)
> m
[,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(m, "dim") dim(m) ヨ緇

茵罨≦絮с筝с若鴻篁吾ссс絖吾сс

> m <- c(1, 2, 3, 4, 5, 6)
> is.vector(m)
[1] TRUE
> dim(m) <- c(2, 3)
> is.vector(m)
[1] FALSE
> is.atomic(m)
[1] TRUE

茵c鴻ц;憗鴻

> is.list(m)
[1] FALSE

茵 2 罨≦с3 罨≦篁ヤс

R с鴻 C++ Java 違c綣с綣Perl 鴻с障c潟ゃ

R с吾с鴻絮堺吾с "class" 絮с篏絖ャcс鴻c絎臂綽荀

> monkey <- "123"
> attr(monkey, "class") <- "animal"
> attr(monkey, "class")
[1] "animal"

attr(monkey, "class") class(monkey) с

膈箴<сclass ∽違劫с筝膣吾сゃ鴻怨

> num <- 1
> attr(a, "class")
NULL
> class(a)
[1] "numeric"

障吾с罨≦絮сc翫∽ class 吾сmatrix 鴻怨

> m <- c(1, 2, 3, 4, 5, 6)
> class(m)
[1] "numeric"
> dim(m) <- c(2, 3)
> class(m)
[1] "matrix"
> attr(m, "class")
NULL

鴻<純荐荐鏆荀R ∽違綣違鴻荀違c篁腟帥障с鴻<純c羂潟с

> respect <- function (x)
+ UseMethod("respect")
> respect.boy <- function (x) paste (x, "kun")
> respect.girl <- function (x) paste (x, "san")
> sazae <- "Huguta Sazae"
> class(sazae) <- "girl"
> masuo <- "Huguta Masuo"
> class(masuo) <- "boy"
> respect(sazae)
[1] "Huguta Sazae san"
> respect(masuo)
[1] "Huguta Masuo kun"
罨≠
HOME


紕膣
薤藕

茯絖
沿
ユ茯


遵医