0
votes

I would like to calculate distance between two groups. I am very confused.

I have a two data sets. One is about a company and one is about employees.

I would like to find out how their age( a company in which an employee is hired and an employee) are similar or not. I think I need to standarize also..

  1. calcuate euclidean distance between each person and a company. (4-5 people in a company)
  2. calculate euclidean distance between each person and a company in industry level.

My dataset is like this:

person person_age    company company_age industry              

1        50             1       5         1

2        40             1       5         1

3        30             2        1        1

4        20             2        1        1

5        25             3        8        2

The following code will reproduce my data.frame:

person <- 1:5
person_age <- c(50,40,30,20,25)
company <- c(1,1,2,2,3)
company_age <- c(5,5,1,1,8)
industry <- c(1,1,1,1,2)
myData <- data.frame(person, person_age, company, company_age, industry)

Please help me. I don't mind using SAS or R. I am very confused.

2
you are correct about being confused. What's your definition of "distance"? - JD Long
I would like to calculate such as euclidean distance. thank you for asking a question. - user976856
Do you mean to find out if the age of the employees in one company is similar to another company? - Luciano Selzer
euclidean distance on which variables? You will never be able to encode in a programming language that which you cannot explain clearly in plain language. - JD Long
I mean that age of employees in one company is similar to age of the company. - user976856

2 Answers

3
votes

So if you just want Euclidean distance on each person's age you can do something like:

d <- dist(myData[c("person","person_age")])

Your question is still incredibly malformed. For example, what does "calcuate [sic] euclidean distance between each person and a company" mean?

If you just want to know the distance between each person and the company they work for, you could code that as:

 with(myData, ((person_age - company_age)^2)^.5 ) 

which is simply the 2d Euclidean distance formula

-4
votes

This post discusses about calculating Euclidean distance. Convert the data into two vectors and follow the steps.