 Open in App
Not now

# 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.

Example 1:

 # data1 with vector of elementsdata1=c(1,2,3,4,5)  # data2 with vector of elementsdata2=c("sravan",'bobby','rohith','gnanu','ojaswi')  # give input to the data which is a dataframedata=data.frame(a1=data1,a2=data2)  # finding standard deviation of dataframe# column 1print(sd(data$a1)) Output:  1.581139 Example 2: ## R  # data1 with vector of elementsdata1=c(1,2,3,4,5)  # data2 with vector of elementsdata2=c(10,20,30,40,50)  # give input to the data which is a# dataframedata=data.frame(a1=data1,a2=data2)  # finding standard deviation of dataframe# column 1print(sd(data$a1))  # finding standard deviation of dataframe# column 2print(sd(data$a2)) Output:  1.581139  15.81139 Example 3: ## R  # data1 with vector of elements (float# values)data1=c(1.0,2,3,4,5,8)  # data2 with vector of elements(float# values)data2=c(10,20.5,30.3,40,50,67.89)  # give input to the data which is a # dataframedata=data.frame(a1=data1,a2=data2)  # finding standard deviation of dataframe # column 1print(sd(data$a1))  # finding standard deviation of dataframe # column 2print(sd(data\$a2))

Output:

 2.483277

 20.86387

My Personal Notes arrow_drop_up