Use endpoints function to get start points instead?
You can create a startpoints
function like this
startpoints <- function (x, on = "months", k = 1) {
head(endpoints(x, on, k) + 1, -1)
}
Understanding function endpoints
Let's prepare sample data :
month <- seq.Date(from=Sys.Date()-5,to=Sys.Date()+10,by="day")
# [1] "2018-06-18" "2018-06-19" "2018-06-20" "2018-06-21" "2018-06-22" "2018-06-23" "2018-06-24" "2018-06-25" "2018-06-26"
# [10] "2018-06-27" "2018-06-28" "2018-06-29" "2018-06-30" "2018-07-01" "2018-07-02" "2018-07-03"
xts::endpoints
gives the index of the last observation of each month, always beginning with 0:
library(xts)
endpoints(month, "months")
# [1] 0 13 16
So if you add 1
, you'll have the index of the first available day of the next month and conveniently, the 0 will be the index of the 1st day of the 1st month:
endpoints(month, "months") + 1
# [1] 1 14 17
The last value is meaningless though, so we drop it:
head(endpoints(month, "months") + 1, -1)
# [1] 1 14
And we end up with your solution:
first.values <- month[head(endpoints(month, "months") + 1, -1)]
# [1] "2018-06-18" "2018-07-01"
An alternate way of doing it:
month <- as.xts(month)
first_as_list <- lapply(split(month,f="month"), function(x) index(x)[1])
do.call(c,first_as_list)
# [1] "2018-06-18" "2018-07-01"
How to update my dictionary to hold both Start and Endpoints
First of all your expected output is not a valid dictionary. I assume however you want to generate:
d = {'a' :
{ 'E' : (x,y) , # EndPoint
'S' : (x,y) } # StartPoint
}
In that case you can simply write:
from collections import defaultdict
points = defaultdict(dict)
for i,stati in enumerate(state):
for j,statij in enumerate(stati):
if statij.isalpha():
low_statij = statij.lower()
if statij.isupper():
points[low_statij]['S'] = (i,j)
else:
points[low_statij]['E'] = (i,j)
This generates:
>>> points
defaultdict(<class 'dict'>, {'b': {'E': (2, 1), 'S': (1, 10)}, 'a': {'E': (0, 0), 'S': (4, 4)}, 'c': {'E': (3, 2), 'S': (0, 4)}})
In case you want to convert it back to a vanilla dictionary, you can call dict
on points
:
>>> dict(points)
{'b': {'E': (2, 1), 'S': (1, 10)}, 'a': {'E': (0, 0), 'S': (4, 4)}, 'c': {'E': (3, 2), 'S': (0, 4)}}
C# Reference: Line updates its EndPoint due to changed from different Line instance
In both SetLength()
and SetAngle()
, you're creating a NEW Point instance to update your Line. This means that particular Line instance will reference the newly created Point, but all the other Line instances will still reference the originally created Point.
Simply change:
EndPoint = new Point(x2, y2);
To:
EndPoint.X = x2;
EndPoint.Y = y2;
Make sure to do this in both of your functions!
Getting data from minute xts objects at particular minute
Time of day subsetting currently only works with a range. You could use UpRatio["T10:14:59.999/T10:15:00"]
instead of last(UpRatio["T10:14:00/T10:15:00"])
. Also note that this will return the 10:15 time for every day in your object.
Related Topics
Get Start and End Index of Runs of Values
Adding Text Labels to Tmap Plot
"Update by Reference" Vs Shallow Copy
Group Data Frame by Pattern in R
Cumulative Sums Over Run Lengths. Can This Loop Be Vectorized
Cannot Install R Tseries, Quadprog ,Xts Packages in Linux
How to Flatten The Data of Different Data Types by Using Sparklyr Package
Numerical Triple Integration in R
Meaning of Error Using . Shorthand Inside Dplyr Function
Spread with Duplicate Identifiers for Rows
R Ddply with Multiple Variables
Combining Date and Time into a Date Column for Plotting
Filtering Single-Column Data Frames
R: Xmleventparse with Large, Varying-Node Xml Input and Conversion to Data Frame
How to Plot Grid Plots on a Same Page
How to Place +/- Plus Minus Operator in Text Annotation of Plot (Ggplot2)