0

How can I create multiple column by type?

Here is what I got:

employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
startdate <- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))
employ.data <- data.frame(employee, salary, date)

This is what I want:

Date Salary John Peter Jolie
xxx   xxx   xxx  xxx   xxx 

Ben
  • 183
  • 8
  • Look into SO questions/answers on 'convert from long to wide'. – arg0naut91 Mar 08 '20 at 15:50
  • I think salaries can change and you want the current salary at each date for each employee, is that correct. – user2332849 Mar 08 '20 at 15:57
  • what values are under the employee names? if you have a salary column, then there is no any other value to be used under the employee names – M_Shimal Mar 08 '20 at 16:00
  • Thanks for answering. The spread function worked. However, the date column is still reocurring from the start every time a new name comes up. so i have alot of N/A's. – Ben Mar 08 '20 at 16:11

0 Answers0