This is a very specific task but I believe the learning from it may be general enough to be of use. I have an oddly designed data set of time stamps that I need to reshape and I need to operate out of the packages that come with a base install. I think seeing is easier than explaining.
The list of named vectors with time stamps:
x <- structure(list(A = c("2.40", ":", "3.00", "5.01", "6.62", ":",
"7.00", "9.00"), B = c("2.40", "5.01", "6.62", ":", "7.00", "9.00"
), C = c("2.40", ":", "3.00", "5.01", "6.62", ":", "7.00", "9.00"
)), .Names = c("A", "B", "C"))
What the list looks like:
> x
[[1]]
[1] "2.40" ":" "3.00" "5.01" "6.62" ":" "7.00" "9.00"
[[2]]
[1] "2.40" "5.01" "6.62" ":" "7.00" "9.00"
[[3]]
[1] "2.40" ":" "3.00" "5.01" "6.62" ":" "7.00" "9.00"
What I’d like:
$A
start end
1 "2.40" "3.00"
2 "5.01" "5.01"
3 "6.62" "7.00"
4 "9.00" "9.00"
$B
start end
1 "2.40" "2.40"
2 "5.01" "5.01"
3 "6.62" "7:00"
4 "9.00" "9.00"
$C
start end
1 "2.40" "3.00"
2 "5.01" "5.01"
3 "6.62" "7.00"
4 "9.00" "9.00"
Where there’s a colon (:) the element on the left is a start value and the element on the right is an end value. If an element is not touching a colon it needs to be repeated and is both the start and end value.
Note: the outcome wouldn’t have quotes if it’s a dataframe vs. a matrix
Is this what you want?