how do i find the average of one variable in a datset in r

To find the average of a single variable in a dataset in R, you can use the mean() function.

Assuming your dataset is named data and the variable you want to find the average for is named var, you can use the following code:

main.r
mean(data$var)
15 chars
2 lines

This code will return the average value of the var variable in the data dataset.

If you want to round the average value to a certain number of decimal places, you can use the round() function. For example, to round the average to 2 decimal places, you can use the following code:

main.r
round(mean(data$var), 2)
25 chars
2 lines

I hope this helps!

gistlibby LogSnag