SAS/R calculate distance between two groups

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.

Answers


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


Need Your Help

Can any one explain me the behaviours of this keyword

javascript jquery element this

I'm little bit confused about the behaviours of this keyword. I was trying to call a function when a button was clicked. But as I know when I call function on click of an element the this should re...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.