Get Standard Deviation of a Column in R dataframe
Last Updated :
07 Apr, 2021
In this article, we are going to find the standard deviation of a column in a dataframe in R Programming Language.
To select the desired column of a dataframe $ is used.
Syntax:
dataframe$column_name
Formula for variance:
where n is the total number of observations and x bar is the mean
Formula for standard deviation:
In the R programming language, for finding standard deviation on set of data, the method used is sd()
Syntax:
sd(data_values)
Where data-values are a vector input or data frame input.
Given below are some examples to help you understand this better
Example 1:
R
data1= c (1,2,3,4,5)
data2= c ( "sravan" , 'bobby' , 'rohith' , 'gnanu' , 'ojaswi' )
data= data.frame (a1=data1,a2=data2)
print ( sd (data$a1))
|
Output:
[1] 1.581139
Example 2:
R
data1= c (1,2,3,4,5)
data2= c (10,20,30,40,50)
data= data.frame (a1=data1,a2=data2)
print ( sd (data$a1))
print ( sd (data$a2))
|
Output:
[1] 1.581139
[1] 15.81139
Example 3:
R
data1= c (1.0,2,3,4,5,8)
data2= c (10,20.5,30.3,40,50,67.89)
data= data.frame (a1=data1,a2=data2)
print ( sd (data$a1))
print ( sd (data$a2))
|
Output:
[1] 2.483277
[1] 20.86387
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...