Description Usage Arguments Details Value Author(s) See Also Examples
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.
1 | find.value.last(data, from, to, value = 1)
|
data |
a |
from |
a |
to |
a |
value |
an |
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.
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.
Emmanuel Rousseaux
findlast, find.value.fun, seq.count.
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
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.