1 개요[ | ]
- 함수 mode()
- 함수 getmode()
2 PHP[ | ]

PHP
CPU
0.0s
MEM
22M
0.1s
Copy
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
orange
3 R[ | ]

R
Copy
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
R
Copy
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 같이 보기[ | ]
편집자 Jmnote Jmnote bot 14.32.144.145
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- PHP (8)
PHP 파일 다운로드 구현 2 (한글 파일명 지원) ― …PHP에서 오라클 DB 사용 ― YoWuPHP 파일 업로드 구현 ― 일리단사오육칠PHP 파일 업로드 구현 ― JmnotePHP 파일 다운로드 구현 2 (한글 파일명 지원) ― AnmkstLib my.php ― 신정섭Lib my.php ― Jmnote로또번호 생성 ―Pinkcrimson