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

 
(같은 사용자의 중간 판 15개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;R rowMeans()
;R rowMeans()
* Form Row Means
* Form Row Means
* "행별 평균", "가로 평균"


<source lang='r'>
==모든 열의 평균==
mydf <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
<syntaxhighlight lang='r' notebook>
English Math
df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
     30   60
english math science
     40   70
30      60  45
     50   80
40     70   60
     60   90
50     80   80
60     90   90
70     90   90
")
")
mydf
df
##  English Math
</syntaxhighlight>
## 1     30  60
<syntaxhighlight lang='r' notebook>
## 2      40  70
rowMeans(df)
## 3      50  80
</syntaxhighlight>
## 4      60  90
<syntaxhighlight lang='r' notebook>
apply(df, 1, mean)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
df$mean <- rowMeans(df)
df
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
df$mean <- apply(df, 1, mean)
df
</syntaxhighlight>


rowMeans(mydf)
==일부 열의 평균==
## [1] 45 55 65 75
<syntaxhighlight lang='r' notebook=2>
apply(mydf, 1, mean)
df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
## [1] 45 55 65 75
id english math science
</source>
1  30      60  45
2  40      70  60
3  50      80  80
4  60      90  90
5  70      90  90
")
df
</syntaxhighlight>
<syntaxhighlight lang='r' notebook=2>
df$mean <- rowMeans(df[,2:4])
df
</syntaxhighlight>
<syntaxhighlight lang='r' notebook=2>
df$mean <- apply(df[,2:4], 1, mean)
df
</syntaxhighlight>


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

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

1 개요[ | ]

R rowMeans()
  • Form Row Means
  • "행별 평균", "가로 평균"

2 모든 열의 평균[ | ]

df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
english math science
30      60   45
40      70   60
50      80   80
60      90   90
70      90   90
")
df
rowMeans(df)
apply(df, 1, mean)
df$mean <- rowMeans(df)
df
df$mean <- apply(df, 1, mean)
df

3 일부 열의 평균[ | ]

df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
id english math science
1  30      60   45
2  40      70   60
3  50      80   80
4  60      90   90
5  70      90   90
")
df
df$mean <- rowMeans(df[,2:4])
df
df$mean <- apply(df[,2:4], 1, mean)
df

4 같이 보기[ | ]

5 참고[ | ]

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