0

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.

JD Long
  • 59,675
  • 58
  • 202
  • 294
user976856
  • 175
  • 2
  • 16

2 Answers2

3

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

JD Long
  • 59,675
  • 58
  • 202
  • 294
-4

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

Community
  • 1
  • 1
  • 3
    PS "Measure theory and Lebesgue integration" -- really? That's a bit like saying "to replace your exhaust system, you should go study metallurgy" ... – Ben Bolker Nov 30 '11 at 18:00