Analysis in R: Basic commands for manipulating data

RAnalytics
スポンサーリンク

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 audibleの登録の紹介

プライム会員限定で2024年7月22日まで3か月無料体験キャンペーン開催中です。無料体験後は月額1,500円で聞き放題です。なお、聞き放題対象外の本はAudible会員であれば非会員価格の30%引きで購入することが可能です。

Amazon audibleはプロのナレーターが朗読した本をアプリで聞くことができるサービスで、オフライン再生も可能です。通勤や作業のお供にAmazon audibleのご登録はいかがでしょうか。

・AmazonのAudible

https://amzn.to/3L4FI5o

Copied title and URL