I have a data frame and I want to convert one of the column to letters to A, B, C, D and create a summarized time:
ticket <- c('1-5444', '1-5444', '1-5444', '1-5444', '1-5444', '1-5444', '1-5445')
person <- c('John','John','Kai', 'John', 'Kai', 'Bob', 'John')
time<- c(NA, 1, 2,1, 3, 4, NA)
df <- data.frame(ticket,person,time)
I want to create a abstract variable called z
, which will take an abstract value for the person
column. For example, in John-John-Kai-John-Kai-Bob
,there are essentially three persons and hence, A-A-B-A-B-C
. So z
will take values of the corresponding actors as shown below:
ticket person time z ztime
1-5444 John NA A 2
1-5444 John 1 A 2
1-5444 Kai 2 B 5
1-5444 John 1 A 2
1-5444 Kai 3 B 5
1-5444 Bob 4 C 4
1-5445 John NA A 0
Then I would like to calculate ztime which tells the sum of amount of time each person has taken. Any thoughts?