함수 mode()

1 개요[ | ]

함수 mode()
함수 getmode()

2 PHP[ | ]

function mode($arr) {
	$count_values = array_count_values($arr);
	$max = max($count_values);
	foreach( $count_values as $key => $count) if( $max == $count ) return $key;
}
$fruits = ['orange','banana','apple','orange','orange','apple'];
echo mode( $fruits ); # orange

3 R[ | ]

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

4 같이 보기[ | ]

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