"R sapply()"의 두 판 사이의 차이

2번째 줄: 2번째 줄:
;R sapply()
;R sapply()


<source lang='r'>
<source lang='r' notebook>
x <- c(2,3,4)
x <- c(2,3,4)
sapply(x, function(n) { n*n })
x
## [1]  4  9 16
x**2
## [1]  4  9 16
</source>
</source>
<source lang='r'>
<source lang='r' notebook>
sapply(x, function(n) { n*n }) ## [1]  4  9 16
</source>
<source lang='r' notebook>
x**2 ## [1]  4  9 16
</source>
<source lang='r' notebook>
movies <- c("SPYDERMAN","BATMAN","VERTIGO","CHINATOWN")
movies <- c("SPYDERMAN","BATMAN","VERTIGO","CHINATOWN")
sapply(movies, tolower)
sapply(movies, tolower)
##  SPYDERMAN      BATMAN    VERTIGO  CHINATOWN
</source>
## "spyderman"    "batman"  "vertigo" "chinatown"
<source lang='r' notebook>
sapply(movies, nchar)
sapply(movies, nchar)
## SPYDERMAN    BATMAN  VERTIGO CHINATOWN
##        9        6        7        9
</source>
</source>
<source lang='r'>
<source lang='r' notebook>
mydf <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
English Math
English Math
     90  60
     90  60
26번째 줄: 27번째 줄:
     60  90
     60  90
")
")
</source>
<source lang='r' notebook>
colMeans(mydf)
colMeans(mydf)
## English    Math
</source>
##      75      75
<source lang='r' notebook>
sapply(mydf, mean)
sapply(mydf, mean)
## English    Math
##      75      75
</source>
</source>



2021년 4월 17일 (토) 15:27 판

1 개요

R sapply()
x <- c(2,3,4)
x
sapply(x, function(n) { n*n }) ## [1]  4  9 16
x**2 ## [1]  4  9 16
movies <- c("SPYDERMAN","BATMAN","VERTIGO","CHINATOWN")
sapply(movies, tolower)
sapply(movies, nchar)
df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
English Math
     90   60
     80   70
     70   80
     60   90
")
colMeans(mydf)
sapply(mydf, mean)

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}