find.value.last: Find the last occurence of a specific value in a 'data.frame'...

Description Usage Arguments Details Value Author(s) See Also Examples

Description

The find.value.last function allows to find the last occurence of a specific value in a set of columns of a data.frame object, and returns these values. You can then retrieve these last values for others sets of columns of the data.frame object.

Usage

1
find.value.last(data, from, to, value = 1)

Arguments

data

a data.frame object.

from

a vector of either column names or column ids from where you want to find where the last occurence of the value is.

to

a list containing in each item the column names or ids of another time-varying variable for which you want to get the last value found in data[,from]. The name of each item is used as column name for the output.

value

an integer, the value/event you are looking for.

Details

This function is useful when working on longitudinal data with attrition problems. It allows to retrieve the last occurence of an event in a specific time-varying variable and then getting the values for other time-varying variables according to the indexs previously reported.

Value

If the to argument is missing, the function returns the ids where the last occurence of the value is for each row of the data argument. It also return a column containing the type of the value retrieved : 1 if the value has been found, NA if the sequence contained only NA values, -1 if the sequence contained non-NA values but no occurence of the value. If the to argument is given, a data.frame containing the corresponding last values on covariates is returned.

Author(s)

Emmanuel Rousseaux

See Also

findlast, find.value.fun, seq.count.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# data.frame example
fv.data.example <- data.frame(
  'unemployment99' = c(0,NA,NA,NA,NA),
  'unemployment00' = c(0,NA,NA,NA,NA),
  'unemployment01' = c(1,0,NA,NA,NA),
  'unemployment02' = c(0,0,0,NA,NA),
  'unemployment03' = c(0,1,NA,NA,NA),
  'unemployment04' = c(NA,1,1,NA,NA),
  'unemployment05' = c(NA,1,1,NA,NA),
  'unemployment06' = c(NA,NA,1,NA,NA),
  'unemployment07' = c(NA,NA,NA,0,NA),
  'unemployment08' = c(NA,NA,NA,0,NA),
  'unemployment09' = c(NA,NA,NA,0,NA),
  'unemployment10' = c(NA,NA,NA,0,NA),
  'unemployment11' = c(NA,NA,NA,0,NA),
  'age99' = c(15,NA,NA,NA,NA),
  'age00' = c(16,NA,NA,NA,NA),
  'age01' = c(17,20,NA,NA,NA),
  'age02' = c(18,21,23,NA,NA),
  'age03' = c(19,22,NA,NA,NA),
  'age04' = c(NA,23,25,NA,NA),
  'age05' = c(NA,24,26,NA,NA),
  'age06' = c(NA,NA,27,NA,NA),
  'age07' = c(NA,NA,NA,29,NA),
  'age08' = c(NA,NA,NA,30,NA),
  'age09' = c(NA,NA,NA,31,NA),
  'age10' = c(NA,NA,NA,32,NA),
  'age11' = c(NA,NA,NA,33,NA),
  'education99' = c(8,NA,NA,NA,NA),
  'education00' = c(8,NA,NA,NA,NA),
  'education01' = c(8,3,NA,NA,NA),
  'education02' = c(8,3,2,NA,NA),
  'education03' = c(8,4,NA,NA,NA),
  'education04' = c(NA,4,2,NA,NA),
  'education05' = c(NA,4,2,NA,NA),
  'education06' = c(NA,NA,3,NA,NA),
  'education07' = c(NA,NA,NA,7,NA),
  'education08' = c(NA,NA,NA,7,NA),
  'education09' = c(NA,NA,NA,7,NA),
  'education10' = c(NA,NA,NA,8,NA),
  'education11' = c(NA,NA,NA,8,NA)
)
# we get the column ids where the last occurence of the value 1 is
find.value.last(
  data = fv.data.example,
  from = 1:13,
  value = 1
)

# we retrieve the last occurence of the value 1 for unemployment, and get corresponding values for the variables age and education
find.value.last(
  data = fv.data.example,
  from = 1:13,
  to = list(
    'age' = 14:26,
    'education' = 27:39
  ),
  value = 1
)

# same operation but here for the value 0
find.value.last(
  data = fv.data.example,
  from = 1:13,
  to = list(
    'age' = 14:26,
    'education' = 27:39
  ),
  value = 0
)

Dataset documentation built on May 2, 2019, 6:09 p.m.