0

I have a column say hight, 120,113,114,113,114,.... until 100. That is, I have 100 hights in my data set.

Now I want to use a fixed formula to calculate a specific value. The formula is:

Hight= SQRT((hight1)^2 + (hight2)2 +(hight3)^2....)/2)

Hight= SQRT((120)^2 + (113)2 +(hight114)^2....)/2)

I was unable to run it using R codes to show the output. Are there any codes to get this data using this formula quickly?

user330
  • 1,256
  • 1
  • 7
  • 12
  • Please read [this post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to ask a good question in R and edit your post accordingly. Thanks. – user438383 Oct 09 '20 at 15:50

1 Answers1

0

You can write functions in R. You just write:

func_name <- function (argument) {
statement
}

You should be able to write formula for calculating height. Try below (I used random 100 heights in array new_data):

height <- function(height_data) {
  power <- (height_data ^ 2)
  data_sum <- sum(power)
  final_data <- data_sum/2
}

new_data <- rep(c(156, 189, 170, 155, 190), 20)

result <- height(new_data)

You should have result in result object

pawmasz
  • 93
  • 1
  • 10
  • Sorry, forgot about it. Should sqrt be before division by 2 or sqrt of whole calculation? I'll edit the comment acordingly – pawmasz Oct 09 '20 at 17:38