"R 최빈값 getmode()"의 두 판 사이의 차이

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


<source lang='r'>
<syntaxhighlight lang='r' run>
getmode <- function(v) {
getmode <- function(v) {
   uniqv <- unique(v)
   uniqv <- unique(v)
8번째 줄: 8번째 줄:
}
}
v <- c(2,1,2,3,1,2)
v <- c(2,1,2,3,1,2)
print( getmode( v ) )
getmode( v )
# 2
</syntaxhighlight>
</source>
<syntaxhighlight lang='r' run>
<source lang='r'>
getmode <- function(v) {
getmode <- function(v) {
   uniqv <- unique(v)
   uniqv <- unique(v)
17번째 줄: 16번째 줄:
}
}
charv <- c("o","it","the","it","it")
charv <- c("o","it","the","it","it")
print( getmode( charv ) )
getmode( charv )
# "it"
</syntaxhighlight>
</source>


==같이 보기==
==같이 보기==

2021년 4월 14일 (수) 01:26 기준 최신판

1 개요[ | ]

R getmode()
getmode <- function(v) {
  uniqv <- unique(v)
  uniqv[which.max(tabulate(match(v, uniqv)))]
}
v <- c(2,1,2,3,1,2)
getmode( v )
getmode <- function(v) {
  uniqv <- unique(v)
  uniqv[which.max(tabulate(match(v, uniqv)))]
}
charv <- c("o","it","the","it","it")
getmode( charv )

2 같이 보기[ | ]

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