本文へスキップ
からだにいいもの

Rのトピックスを中心に『まだ、まだ、知らない、役に立つ情報?』を発信します。

Analysis in R: Basic commands for manipulating data

Many of you may use Excel to analyze data, but using R may reveal facts that Excel could not. We encourage you to use R to enrich your analysis.

Here are some basic commands, and “KARADA GOOD” introduces a number of packages. Please have a look.

How to find the maximum and minimum values

I think the maximum and minimum values are very important indicators.

Commands used in R

Max:max(x, na.rm = FALSE)

Min:min(x, na.rm = FALSE)

# Missing values are excluded by setting na.rm to TRUE
# The default is FALSE
x <- c(NA, 3, 4, 12, 100)
# na.rm is TRUE
max(x, na.rm = TRUE)
[1] 100
# na.rm is FALSE
max(x, na.rm = FALSE)
[1] NA
min(x, na.rm = TRUE)
[1] 3
# na.rm is FALSE
min(x, na.rm = FALSE)
スポンサーリンク

Row and column sums and averages

This can be done in Excel, but there are some tasks, such as specifying a range, that can lead to errors.

Commands used in R

Row Sum:rowSums(x, na.rm = FALSE)

Row Mean:rowMeans(x, na.rm = FALSE)

Col Sum:colSums(x, na.rm = FALSE)

Col mean:colMeans(x, na.rm = FALSE)

# Missing values are excluded by setting na.rm to TRUE
# The default is FALSE
# Create a 3*3 matrix
x <- matrix(c(8, 5, 6, 3, 9, 3, 1, 2, 3), 3, 3)
x 
  [,1] [,2] [,3]
[1,]  8  3  1 
[2,]  5  9  2 
[3,]  6  3  3

#Row Sum
rowSums(x)
[1] 12 16 12

#Row Mean
rowMeans(x)
[1] 4.000000 5.333333 4.000000

#Col Sum
colSums(x)
[1] 19 15 6
#Col Mean
colMeans(x)
[1] 6.333333 5.000000 2.000000

I hope this makes your analysis a little easier !!

スポンサーリンク
価格および配送状況は変更される場合があります。購入時は商品ページをご確認ください。
当サイトに表示されている商品情報はAmazonから提供されたものであり、更新または削除される場合があります。
karada-goodはAmazonアソシエイトとして、適格販売により収入を得ています。