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

 
(사용자 2명의 중간 판 6개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;R sapply()
;R sapply()


<source lang='r'>
<syntaxhighlight lang='r' notebook>
x <- c(2,3,4)
x <- c(2,3,4)
sapply(x, function(n) { n*n })
x
## [1]  4  9 16
</syntaxhighlight>
x**2
<syntaxhighlight lang='r' notebook>
## [1]  4  9 16
sapply(x, function(n) { n*n }) ## [1]  4  9 16
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r' notebook>
x**2 ## [1]  4  9 16
</syntaxhighlight>
<syntaxhighlight 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
</syntaxhighlight>
## "spyderman"    "batman"  "vertigo" "chinatown"
<syntaxhighlight lang='r' notebook>
sapply(movies, nchar)
sapply(movies, nchar)
## SPYDERMAN    BATMAN   VERTIGO CHINATOWN
</syntaxhighlight>
##        9        6        7        9
<syntaxhighlight lang='r' notebook>
</source>
df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
English Math
    90  60
    80   70
    70  80
    60  90
")
df
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
colMeans(df)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
sapply(df, mean)
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[R apply()]]
* [[R lapply()]]
* [[R lapply()]]
* [[R colMeans()]]
* [[R apply() 패밀리]]
* [[R apply() 패밀리]]
* [[함수 map()]]
* [[함수 map()]]
28번째 줄: 47번째 줄:


[[분류: R base]]
[[분류: R base]]
[[분류: map()]]

2022년 4월 19일 (화) 11:41 기준 최신판

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
")
df
colMeans(df)
sapply(df, mean)

2 같이 보기[ | ]

3 참고[ | ]

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