Support
Quality
Security
License
Reuse
kandi has reviewed storm and discovered the below as its top functions. This is intended to give you an instant insight into storm implemented functionality, and help decide if they suit your requirements.
Create a new fork of apache/incubator-storm
Point your existing clone to the new fork: git remote remove origin git remote add origin git@github.com:username/incubator-storm.git
Migrating Git Repos from nathanmarz/storm to apache/incubator-storm
git remote remove origin
git remote add origin git@github.com:username/incubator-storm.git
R - dplyr- Reducing data package 'storms'
storm_ID <- storms %>%
select(year,month,name) %>%
group_by(year,month,name) %>%
mutate(ID = stringr::str_c(name, cur_group_id()))
storms %>%
group_by(name) %>%
mutate(consec_helper = cumsum(c(1, diff(year) != 1))) %>%
group_by(name, consec_helper) %>%
filter(n() > 1)
name year
<chr> <dbl>
1 Zeta 2005
2 Zeta 2006
-----------------------
storm_ID <- storms %>%
select(year,month,name) %>%
group_by(year,month,name) %>%
mutate(ID = stringr::str_c(name, cur_group_id()))
storms %>%
group_by(name) %>%
mutate(consec_helper = cumsum(c(1, diff(year) != 1))) %>%
group_by(name, consec_helper) %>%
filter(n() > 1)
name year
<chr> <dbl>
1 Zeta 2005
2 Zeta 2006
-----------------------
storm_ID <- storms %>%
select(year,month,name) %>%
group_by(year,month,name) %>%
mutate(ID = stringr::str_c(name, cur_group_id()))
storms %>%
group_by(name) %>%
mutate(consec_helper = cumsum(c(1, diff(year) != 1))) %>%
group_by(name, consec_helper) %>%
filter(n() > 1)
name year
<chr> <dbl>
1 Zeta 2005
2 Zeta 2006
-----------------------
suppressPackageStartupMessages(library(dplyr))
data("storms", package = "dplyr")
Thresh <- 5
storms %>%
count(name, year, month, day) %>%
group_by(name) %>%
mutate(Date = as.Date(ISOdate(year, month, day)),
DDiff = c(0, diff(Date)) > Thresh,
DDiff = cumsum(DDiff)) %>%
group_by(name, DDiff) %>%
mutate(name = ifelse(DDiff > 0, paste(name, cur_group_id(), sep = "."), name)) %>%
ungroup() %>%
group_by(name) %>%
summarise(name = first(name),
year = first(year),
n = sum(n))
#> # A tibble: 512 x 3
#> name year n
#> <chr> <dbl> <int>
#> 1 AL011993 1993 8
#> 2 AL012000 2000 4
#> 3 AL021992 1992 5
#> 4 AL021994 1994 6
#> 5 AL021999 1999 4
#> 6 AL022000 2000 12
#> 7 AL022001 2001 5
#> 8 AL022003 2003 4
#> 9 AL022006 2006 5
#> 10 AL031987 1987 32
#> # ... with 502 more rows
suppressPackageStartupMessages(library(dplyr))
data("storms", package = "dplyr")
Thresh <- 5
storms %>%
count(name, year, month, day) %>%
group_by(name) %>%
mutate(Date = as.Date(ISOdate(year, month, day)),
DDiff = c(0, diff(Date)) > Thresh,
DDiff = cumsum(DDiff)) %>%
group_by(name, DDiff) %>%
mutate(name = ifelse(DDiff > 0, paste(name, cur_group_id(), sep = "."), name)) %>%
ungroup() %>%
group_by(name) %>%
summarise(name = first(name),
year = first(year),
n = sum(n)) -> rui
id <- c()
j <- 1
k <- 1
for(i in storms$name) {
if(k-1 == 0){
id <- append(id, j)
k <- k+1
next
}
if(i != storms$name[k-1])
{
j <- j+1
}
id <- append(id, j)
k <- k+1
}
cbind(storms, id) %>%
count(name, id) -> storm_count
# two rows
anti_join(
rui %>% mutate(name = sub("\\.\\d+$", "", name)),
storm_count,
by = c("name", "n")
)
#> # A tibble: 2 x 3
#> name year n
#> <chr> <dbl> <int>
#> 1 Dorian 2013 16
#> 2 Dorian 2013 4
# just one row
anti_join(
storm_count,
rui %>% mutate(name = sub("\\.\\d+$", "", name)),
by = c("name", "n")
)
#> name id n
#> 1 Dorian 397 20
# see here the dates of 2013-07-27 and 2013-08-02
storms %>%
filter(name == "Dorian", year == 2013) %>%
count(name, year, month, day)
#> # A tibble: 7 x 5
#> name year month day n
#> <chr> <dbl> <dbl> <int> <int>
#> 1 Dorian 2013 7 23 1
#> 2 Dorian 2013 7 24 4
#> 3 Dorian 2013 7 25 4
#> 4 Dorian 2013 7 26 4
#> 5 Dorian 2013 7 27 3
#> 6 Dorian 2013 8 2 1
#> 7 Dorian 2013 8 3 3
-----------------------
suppressPackageStartupMessages(library(dplyr))
data("storms", package = "dplyr")
Thresh <- 5
storms %>%
count(name, year, month, day) %>%
group_by(name) %>%
mutate(Date = as.Date(ISOdate(year, month, day)),
DDiff = c(0, diff(Date)) > Thresh,
DDiff = cumsum(DDiff)) %>%
group_by(name, DDiff) %>%
mutate(name = ifelse(DDiff > 0, paste(name, cur_group_id(), sep = "."), name)) %>%
ungroup() %>%
group_by(name) %>%
summarise(name = first(name),
year = first(year),
n = sum(n))
#> # A tibble: 512 x 3
#> name year n
#> <chr> <dbl> <int>
#> 1 AL011993 1993 8
#> 2 AL012000 2000 4
#> 3 AL021992 1992 5
#> 4 AL021994 1994 6
#> 5 AL021999 1999 4
#> 6 AL022000 2000 12
#> 7 AL022001 2001 5
#> 8 AL022003 2003 4
#> 9 AL022006 2006 5
#> 10 AL031987 1987 32
#> # ... with 502 more rows
suppressPackageStartupMessages(library(dplyr))
data("storms", package = "dplyr")
Thresh <- 5
storms %>%
count(name, year, month, day) %>%
group_by(name) %>%
mutate(Date = as.Date(ISOdate(year, month, day)),
DDiff = c(0, diff(Date)) > Thresh,
DDiff = cumsum(DDiff)) %>%
group_by(name, DDiff) %>%
mutate(name = ifelse(DDiff > 0, paste(name, cur_group_id(), sep = "."), name)) %>%
ungroup() %>%
group_by(name) %>%
summarise(name = first(name),
year = first(year),
n = sum(n)) -> rui
id <- c()
j <- 1
k <- 1
for(i in storms$name) {
if(k-1 == 0){
id <- append(id, j)
k <- k+1
next
}
if(i != storms$name[k-1])
{
j <- j+1
}
id <- append(id, j)
k <- k+1
}
cbind(storms, id) %>%
count(name, id) -> storm_count
# two rows
anti_join(
rui %>% mutate(name = sub("\\.\\d+$", "", name)),
storm_count,
by = c("name", "n")
)
#> # A tibble: 2 x 3
#> name year n
#> <chr> <dbl> <int>
#> 1 Dorian 2013 16
#> 2 Dorian 2013 4
# just one row
anti_join(
storm_count,
rui %>% mutate(name = sub("\\.\\d+$", "", name)),
by = c("name", "n")
)
#> name id n
#> 1 Dorian 397 20
# see here the dates of 2013-07-27 and 2013-08-02
storms %>%
filter(name == "Dorian", year == 2013) %>%
count(name, year, month, day)
#> # A tibble: 7 x 5
#> name year month day n
#> <chr> <dbl> <dbl> <int> <int>
#> 1 Dorian 2013 7 23 1
#> 2 Dorian 2013 7 24 4
#> 3 Dorian 2013 7 25 4
#> 4 Dorian 2013 7 26 4
#> 5 Dorian 2013 7 27 3
#> 6 Dorian 2013 8 2 1
#> 7 Dorian 2013 8 3 3
-----------------------
install.packages(dplyr)
library(dplyr)
id <- c()
j <- 1
k <- 1
for(i in storms$name) {
if(k-1 == 0){
id <- append(id, j)
k <- k+1
next
}
if(i != storms$name[k-1])
{
j <- j+1
}
id <- append(id, j)
k <- k+1
}
storms <- cbind(storms, id)
View(storms)
How to update a SelectizeInput depending on a textInput in Shiny
my_list <- reactive({
if (!input$my_input == "") {
data <- as.data.frame(storms)
res <- subset(data, grepl(pattern = str_to_sentence(input$my_input), data$name), name)
res <- as.factor(res$name)
return(res)
}
})
Print says the whole variable
TEMPLATE = """{header}
"Looks like this storm won't stop for another {days}, we will have to wait"
(You can barely hear him but thats all you hear)"""
TEMPLATE.format(
header="-Captain Strand-",
days=days + playerguess,
)
>>> print(TEMPLATE.format(
... header="-Captain Strand-",
... days=days + playerguess,
... ))
-Captain Strand-
"Looks like this storm won't stop for another 5, we will have to wait"
(You can barely hear him but thats all you hear)
>>> example = ("Looks like this storm won't stop for another ", days + playerguess, " we will have to wait")
>>> example # example is a tuple of strings
("Looks like this storm won't stop for another ", 5, ' we will have to wait')
>>> example = "".join(("Looks like this storm won't stop for another ", str(days + playerguess), " we will have to wait"))
>>> example # example is a single string
"Looks like this storm won't stop for another 5 we will have to wait"
-----------------------
TEMPLATE = """{header}
"Looks like this storm won't stop for another {days}, we will have to wait"
(You can barely hear him but thats all you hear)"""
TEMPLATE.format(
header="-Captain Strand-",
days=days + playerguess,
)
>>> print(TEMPLATE.format(
... header="-Captain Strand-",
... days=days + playerguess,
... ))
-Captain Strand-
"Looks like this storm won't stop for another 5, we will have to wait"
(You can barely hear him but thats all you hear)
>>> example = ("Looks like this storm won't stop for another ", days + playerguess, " we will have to wait")
>>> example # example is a tuple of strings
("Looks like this storm won't stop for another ", 5, ' we will have to wait')
>>> example = "".join(("Looks like this storm won't stop for another ", str(days + playerguess), " we will have to wait"))
>>> example # example is a single string
"Looks like this storm won't stop for another 5 we will have to wait"
-----------------------
TEMPLATE = """{header}
"Looks like this storm won't stop for another {days}, we will have to wait"
(You can barely hear him but thats all you hear)"""
TEMPLATE.format(
header="-Captain Strand-",
days=days + playerguess,
)
>>> print(TEMPLATE.format(
... header="-Captain Strand-",
... days=days + playerguess,
... ))
-Captain Strand-
"Looks like this storm won't stop for another 5, we will have to wait"
(You can barely hear him but thats all you hear)
>>> example = ("Looks like this storm won't stop for another ", days + playerguess, " we will have to wait")
>>> example # example is a tuple of strings
("Looks like this storm won't stop for another ", 5, ' we will have to wait')
>>> example = "".join(("Looks like this storm won't stop for another ", str(days + playerguess), " we will have to wait"))
>>> example # example is a single string
"Looks like this storm won't stop for another 5 we will have to wait"
How to create optimized schedule that avoids duplicates
def combinations(matches, day, schedules, current):
"""Backtracking function for selecting unique schedules."""
# base case when you have a match from each day
if day > max(matches.keys()):
schedules.append(current[:])
return
# skip over days where there are no matches
while day not in matches:
day += 1
# select one match for the current date
for i in range(len(matches[day])):
teams = matches[day][i]
current_teams = [j for i in current for j in i]
# check if the teams are already in the current schedule
if teams[0] in current_teams or teams[1] in current_teams:
continue
del matches[day][i]
# recursive case
combinations(matches, day + 1, schedules, current + [teams])
matches[day].insert(i,teams)
return
def format(inp):
"""Formats input data into a dictionary."""
lines = inp.split("\n")[2:] # split lines of input data
matches = [(line.split("|")[1:-1]) for line in lines]
schedule = {}
# add matches to dict with date as key and matches as value.
for day, match in matches:
day = int(day.strip())
teams = match.strip().split(" vs ")
try:
schedule[day].append(teams)
except KeyError:
schedule[day] = [teams]
ideal = []
# use backtracking algorithm to get desired results
combinations(schedule, 1, ideal, [])
show_schedules(ideal)
def show_schedules(results):
for i, x in enumerate(results):
print(f"Schedule {i+1}")
for day, match in enumerate(x):
print(f"Day: {day+1} - {match[0]} vs. {match[1]}")
print("\n")
format(inp) # <- entry point:`inp` is the pre-formatted data `str`
Schedule 1
Day: 1 - hot ice vs. playerz
Day: 2 - avalanche vs. cold force
Day: 3 - quiet storm vs. freeze
Day: 4 - out of order vs. game spot
Day: 5 - slick ice vs. caps
Day: 6 - rare air vs. in too deep
Schedule 2
Day: 1 - hot ice vs. playerz
Day: 2 - avalanche vs. cold force
Day: 3 - 4x4's vs. out of order
Day: 4 - cold as ice vs. rare air
Day: 5 - blizzard vs. quiet storm
Day: 6 - game spot vs. freeze
-----------------------
def combinations(matches, day, schedules, current):
"""Backtracking function for selecting unique schedules."""
# base case when you have a match from each day
if day > max(matches.keys()):
schedules.append(current[:])
return
# skip over days where there are no matches
while day not in matches:
day += 1
# select one match for the current date
for i in range(len(matches[day])):
teams = matches[day][i]
current_teams = [j for i in current for j in i]
# check if the teams are already in the current schedule
if teams[0] in current_teams or teams[1] in current_teams:
continue
del matches[day][i]
# recursive case
combinations(matches, day + 1, schedules, current + [teams])
matches[day].insert(i,teams)
return
def format(inp):
"""Formats input data into a dictionary."""
lines = inp.split("\n")[2:] # split lines of input data
matches = [(line.split("|")[1:-1]) for line in lines]
schedule = {}
# add matches to dict with date as key and matches as value.
for day, match in matches:
day = int(day.strip())
teams = match.strip().split(" vs ")
try:
schedule[day].append(teams)
except KeyError:
schedule[day] = [teams]
ideal = []
# use backtracking algorithm to get desired results
combinations(schedule, 1, ideal, [])
show_schedules(ideal)
def show_schedules(results):
for i, x in enumerate(results):
print(f"Schedule {i+1}")
for day, match in enumerate(x):
print(f"Day: {day+1} - {match[0]} vs. {match[1]}")
print("\n")
format(inp) # <- entry point:`inp` is the pre-formatted data `str`
Schedule 1
Day: 1 - hot ice vs. playerz
Day: 2 - avalanche vs. cold force
Day: 3 - quiet storm vs. freeze
Day: 4 - out of order vs. game spot
Day: 5 - slick ice vs. caps
Day: 6 - rare air vs. in too deep
Schedule 2
Day: 1 - hot ice vs. playerz
Day: 2 - avalanche vs. cold force
Day: 3 - 4x4's vs. out of order
Day: 4 - cold as ice vs. rare air
Day: 5 - blizzard vs. quiet storm
Day: 6 - game spot vs. freeze
Problem with non-standard evaluation in disk.frame objects using data.table syntax
storms_df[name %like% "^A"]
nm <- "^A"
storms_df[name %like% nm]
grep1 <- function(dfr, storm_name) { dfr[name %like% "^A"]; }
grep1(storms_df)
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
grep3 <- function(dfr, storm_name) {
eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
}
grep3(storms_df, "^A")
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79.0 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79.0 tropical depression -1 25 1013 NA NA
# 3: Amy 1975 6 27 12 29.5 -79.0 tropical depression -1 25 1013 NA NA
# ...
debug(grep3)
grep3(storms_df, "^A")
# debugging in: grep3(storms_df, "^A")
# debug at #1: {
# eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
# }
# Browse[2]>
substitute(dfr[name %like% storm_name], list(storm_name = storm_name))
# dfr[name %like% "^A"]
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
### but let's pre-define `storm_name` outside of the function,
### then re-define the function (no change)
storm_name <- "^A"
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
head(grep2(storms_df, "^A"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
head(grep2(storms_df, "^B"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
bench::mark(
raw = dfr[name %like% "^A"],
subst = eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name))),
iterations = 1000
)
# # A tibble: 2 x 13
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list>
# 1 raw 12.9ms 16.8ms 55.2 1.69MB 3.97 933 67 16.9s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
# 2 subst 12.8ms 15.8ms 60.5 1.69MB 3.25 949 51 15.7s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
-----------------------
storms_df[name %like% "^A"]
nm <- "^A"
storms_df[name %like% nm]
grep1 <- function(dfr, storm_name) { dfr[name %like% "^A"]; }
grep1(storms_df)
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
grep3 <- function(dfr, storm_name) {
eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
}
grep3(storms_df, "^A")
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79.0 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79.0 tropical depression -1 25 1013 NA NA
# 3: Amy 1975 6 27 12 29.5 -79.0 tropical depression -1 25 1013 NA NA
# ...
debug(grep3)
grep3(storms_df, "^A")
# debugging in: grep3(storms_df, "^A")
# debug at #1: {
# eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
# }
# Browse[2]>
substitute(dfr[name %like% storm_name], list(storm_name = storm_name))
# dfr[name %like% "^A"]
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
### but let's pre-define `storm_name` outside of the function,
### then re-define the function (no change)
storm_name <- "^A"
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
head(grep2(storms_df, "^A"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
head(grep2(storms_df, "^B"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
bench::mark(
raw = dfr[name %like% "^A"],
subst = eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name))),
iterations = 1000
)
# # A tibble: 2 x 13
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list>
# 1 raw 12.9ms 16.8ms 55.2 1.69MB 3.97 933 67 16.9s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
# 2 subst 12.8ms 15.8ms 60.5 1.69MB 3.25 949 51 15.7s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
-----------------------
storms_df[name %like% "^A"]
nm <- "^A"
storms_df[name %like% nm]
grep1 <- function(dfr, storm_name) { dfr[name %like% "^A"]; }
grep1(storms_df)
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
grep3 <- function(dfr, storm_name) {
eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
}
grep3(storms_df, "^A")
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79.0 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79.0 tropical depression -1 25 1013 NA NA
# 3: Amy 1975 6 27 12 29.5 -79.0 tropical depression -1 25 1013 NA NA
# ...
debug(grep3)
grep3(storms_df, "^A")
# debugging in: grep3(storms_df, "^A")
# debug at #1: {
# eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
# }
# Browse[2]>
substitute(dfr[name %like% storm_name], list(storm_name = storm_name))
# dfr[name %like% "^A"]
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
### but let's pre-define `storm_name` outside of the function,
### then re-define the function (no change)
storm_name <- "^A"
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
head(grep2(storms_df, "^A"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
head(grep2(storms_df, "^B"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
bench::mark(
raw = dfr[name %like% "^A"],
subst = eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name))),
iterations = 1000
)
# # A tibble: 2 x 13
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list>
# 1 raw 12.9ms 16.8ms 55.2 1.69MB 3.97 933 67 16.9s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
# 2 subst 12.8ms 15.8ms 60.5 1.69MB 3.25 949 51 15.7s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
-----------------------
storms_df[name %like% "^A"]
nm <- "^A"
storms_df[name %like% nm]
grep1 <- function(dfr, storm_name) { dfr[name %like% "^A"]; }
grep1(storms_df)
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
grep3 <- function(dfr, storm_name) {
eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
}
grep3(storms_df, "^A")
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79.0 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79.0 tropical depression -1 25 1013 NA NA
# 3: Amy 1975 6 27 12 29.5 -79.0 tropical depression -1 25 1013 NA NA
# ...
debug(grep3)
grep3(storms_df, "^A")
# debugging in: grep3(storms_df, "^A")
# debug at #1: {
# eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
# }
# Browse[2]>
substitute(dfr[name %like% storm_name], list(storm_name = storm_name))
# dfr[name %like% "^A"]
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
### but let's pre-define `storm_name` outside of the function,
### then re-define the function (no change)
storm_name <- "^A"
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
head(grep2(storms_df, "^A"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
head(grep2(storms_df, "^B"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
bench::mark(
raw = dfr[name %like% "^A"],
subst = eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name))),
iterations = 1000
)
# # A tibble: 2 x 13
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list>
# 1 raw 12.9ms 16.8ms 55.2 1.69MB 3.97 933 67 16.9s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
# 2 subst 12.8ms 15.8ms 60.5 1.69MB 3.25 949 51 15.7s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
-----------------------
storms_df[name %like% "^A"]
nm <- "^A"
storms_df[name %like% nm]
grep1 <- function(dfr, storm_name) { dfr[name %like% "^A"]; }
grep1(storms_df)
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
grep3 <- function(dfr, storm_name) {
eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
}
grep3(storms_df, "^A")
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79.0 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79.0 tropical depression -1 25 1013 NA NA
# 3: Amy 1975 6 27 12 29.5 -79.0 tropical depression -1 25 1013 NA NA
# ...
debug(grep3)
grep3(storms_df, "^A")
# debugging in: grep3(storms_df, "^A")
# debug at #1: {
# eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
# }
# Browse[2]>
substitute(dfr[name %like% storm_name], list(storm_name = storm_name))
# dfr[name %like% "^A"]
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
### but let's pre-define `storm_name` outside of the function,
### then re-define the function (no change)
storm_name <- "^A"
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
head(grep2(storms_df, "^A"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
head(grep2(storms_df, "^B"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
bench::mark(
raw = dfr[name %like% "^A"],
subst = eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name))),
iterations = 1000
)
# # A tibble: 2 x 13
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list>
# 1 raw 12.9ms 16.8ms 55.2 1.69MB 3.97 933 67 16.9s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
# 2 subst 12.8ms 15.8ms 60.5 1.69MB 3.25 949 51 15.7s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
-----------------------
storms_df[name %like% "^A"]
nm <- "^A"
storms_df[name %like% nm]
grep1 <- function(dfr, storm_name) { dfr[name %like% "^A"]; }
grep1(storms_df)
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
grep3 <- function(dfr, storm_name) {
eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
}
grep3(storms_df, "^A")
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79.0 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79.0 tropical depression -1 25 1013 NA NA
# 3: Amy 1975 6 27 12 29.5 -79.0 tropical depression -1 25 1013 NA NA
# ...
debug(grep3)
grep3(storms_df, "^A")
# debugging in: grep3(storms_df, "^A")
# debug at #1: {
# eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
# }
# Browse[2]>
substitute(dfr[name %like% storm_name], list(storm_name = storm_name))
# dfr[name %like% "^A"]
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
### but let's pre-define `storm_name` outside of the function,
### then re-define the function (no change)
storm_name <- "^A"
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
head(grep2(storms_df, "^A"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
head(grep2(storms_df, "^B"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
bench::mark(
raw = dfr[name %like% "^A"],
subst = eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name))),
iterations = 1000
)
# # A tibble: 2 x 13
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list>
# 1 raw 12.9ms 16.8ms 55.2 1.69MB 3.97 933 67 16.9s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
# 2 subst 12.8ms 15.8ms 60.5 1.69MB 3.25 949 51 15.7s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
-----------------------
storms_df[name %like% "^A"]
nm <- "^A"
storms_df[name %like% nm]
grep1 <- function(dfr, storm_name) { dfr[name %like% "^A"]; }
grep1(storms_df)
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
grep3 <- function(dfr, storm_name) {
eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
}
grep3(storms_df, "^A")
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79.0 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79.0 tropical depression -1 25 1013 NA NA
# 3: Amy 1975 6 27 12 29.5 -79.0 tropical depression -1 25 1013 NA NA
# ...
debug(grep3)
grep3(storms_df, "^A")
# debugging in: grep3(storms_df, "^A")
# debug at #1: {
# eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name)))
# }
# Browse[2]>
substitute(dfr[name %like% storm_name], list(storm_name = storm_name))
# dfr[name %like% "^A"]
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
grep2(storms_df, "^A")
# Error in .checkTypos(e, names_x) :
# Object 'storm_name' not found amongst name, year, month, day, hour and 8 more
### but let's pre-define `storm_name` outside of the function,
### then re-define the function (no change)
storm_name <- "^A"
grep2 <- function(dfr, storm_name) { dfr[name %like% storm_name]; }
head(grep2(storms_df, "^A"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
head(grep2(storms_df, "^B"), 2)
# name year month day hour lat long status category wind pressure ts_diameter hu_diameter
# <char> <num> <num> <int> <num> <num> <num> <char> <ord> <int> <int> <num> <num>
# 1: Amy 1975 6 27 0 27.5 -79 tropical depression -1 25 1013 NA NA
# 2: Amy 1975 6 27 6 28.5 -79 tropical depression -1 25 1013 NA NA
bench::mark(
raw = dfr[name %like% "^A"],
subst = eval(substitute(dfr[name %like% storm_name], list(storm_name = storm_name))),
iterations = 1000
)
# # A tibble: 2 x 13
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list>
# 1 raw 12.9ms 16.8ms 55.2 1.69MB 3.97 933 67 16.9s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
# 2 subst 12.8ms 15.8ms 60.5 1.69MB 3.25 949 51 15.7s <data.table [990 x 13]> <Rprofmem [669 x 3]> <bench_tm [1,000]> <tibble [1,000 x 3]>
simplify java stream to return an error message
Stream<String> stream = Files.lines(path);
Stream<String> filteredStream= stream .filter(str -> str.length() > 12);
Stream<String> matching = filteredStream.filter(str -> Pattern.matches(regex, str));
Stream<String> matching = filteredStream.filter(str -> {
if(str.length() > 12 && Pattern.matches(regex, str))
return true;
return false;
});
try{
Stream<String> matching = filteredStream.filter(str -> {
if(str.length() > 11 )
throw new Exception("Item must not exceed 12 numbers");
if(Pattern.matches(regex, str))
return true;
throw new Exception("Invalid Item format");
});
}
catch(Exception e){
log.error(e);
message = e;
}
-----------------------
Stream<String> stream = Files.lines(path);
Stream<String> filteredStream= stream .filter(str -> str.length() > 12);
Stream<String> matching = filteredStream.filter(str -> Pattern.matches(regex, str));
Stream<String> matching = filteredStream.filter(str -> {
if(str.length() > 12 && Pattern.matches(regex, str))
return true;
return false;
});
try{
Stream<String> matching = filteredStream.filter(str -> {
if(str.length() > 11 )
throw new Exception("Item must not exceed 12 numbers");
if(Pattern.matches(regex, str))
return true;
throw new Exception("Invalid Item format");
});
}
catch(Exception e){
log.error(e);
message = e;
}
-----------------------
Stream<String> stream = Files.lines(path);
Stream<String> filteredStream= stream .filter(str -> str.length() > 12);
Stream<String> matching = filteredStream.filter(str -> Pattern.matches(regex, str));
Stream<String> matching = filteredStream.filter(str -> {
if(str.length() > 12 && Pattern.matches(regex, str))
return true;
return false;
});
try{
Stream<String> matching = filteredStream.filter(str -> {
if(str.length() > 11 )
throw new Exception("Item must not exceed 12 numbers");
if(Pattern.matches(regex, str))
return true;
throw new Exception("Invalid Item format");
});
}
catch(Exception e){
log.error(e);
message = e;
}
How to plot a point on a time series in python
lati = stormtrack_lat.values
loni = stormtrack_lon.values
timei = stormtrack_datetime.values
fig2 = plt.figure(figsize=(20, 20), dpi=300)
for i, dummy in enumerate(lati):
dsloc = SSTskin_file.sel(lon=loni[i], lat=lati[i], method='nearest')
dstime = SSTskin_file.sel(time=timei[i], lon=loni[i], lat=lati[i], method='nearest')
skin_celsius = (dsloc['analysed_sst']) - 273.15
timesteps = dsloc.time.values
timestep = dstime.time.values
timevalue = ((dstime['analysed_sst']).values) - 273.15
lineplot = plt.plot(timesteps, skin_celsius )
dotplot = plt.plot(timestep, timevalue, "or")
plt.title('Skin SST over time at storm track locations', fontsize = 20 )
plt.xlabel('Date', fontsize = 16)
plt.ylabel('Skin SST in $^{\circ}C$', fontsize = 16)
plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)
#plt.legend(lineplot) #Here I would like to plot the legend for the line plots (time series data). I want to indicate the location (longitude and latitude) of the time series
plt.legend(dotplot[:1], ['Storm track at location and time'], fontsize = 16);
fig2.savefig('SSTskin_storm_timeseries_test.png', bbox_inches='tight')
How to make the images bigger when clicked? JavaScrpit
<div class="backdrop">
<div class="popup">
<img src="" class="popup-image" />
</div>
</div>
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
width: 500px;
height: auto;
top: 50%; // to put it in the middle
left: 50%;
transform: translate(-50%, -50%);
-----------------------
<div class="backdrop">
<div class="popup">
<img src="" class="popup-image" />
</div>
</div>
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
width: 500px;
height: auto;
top: 50%; // to put it in the middle
left: 50%;
transform: translate(-50%, -50%);
-----------------------
<div class="backdrop">
<div class="popup">
<img src="" class="popup-image" />
</div>
</div>
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
width: 500px;
height: auto;
top: 50%; // to put it in the middle
left: 50%;
transform: translate(-50%, -50%);
-----------------------
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<img src="" id="modal-image" />
</div>
</div>
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 50px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
margin: auto;
text-align: center;
}
.modal-image {
display: inline-block;
}
// Get the gallery box
var imageBox1 = document.getElementById("imageBox1");
// Get the modal image tag
var modal = document.getElementById("myModal");
var modalImage = document.getElementById("modal-image");
// When the user clicks the big picture, set the image and open the modal
imageBox1.onclick = function (e) {
var src = e.srcElement.src;
modal.style.display = "block";
modalImage.src = src;
};
-----------------------
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<img src="" id="modal-image" />
</div>
</div>
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 50px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
margin: auto;
text-align: center;
}
.modal-image {
display: inline-block;
}
// Get the gallery box
var imageBox1 = document.getElementById("imageBox1");
// Get the modal image tag
var modal = document.getElementById("myModal");
var modalImage = document.getElementById("modal-image");
// When the user clicks the big picture, set the image and open the modal
imageBox1.onclick = function (e) {
var src = e.srcElement.src;
modal.style.display = "block";
modalImage.src = src;
};
-----------------------
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<img src="" id="modal-image" />
</div>
</div>
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 50px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
margin: auto;
text-align: center;
}
.modal-image {
display: inline-block;
}
// Get the gallery box
var imageBox1 = document.getElementById("imageBox1");
// Get the modal image tag
var modal = document.getElementById("myModal");
var modalImage = document.getElementById("modal-image");
// When the user clicks the big picture, set the image and open the modal
imageBox1.onclick = function (e) {
var src = e.srcElement.src;
modal.style.display = "block";
modalImage.src = src;
};
Clustering in R using K-mean
library(fastDummies)
df_dummy <- dummy_columns(df, select_columns = "Yeast", remove_selected_columns = TRUE)
res <- NbClust(df_dummy[2:9], min.nc = 2, max.nc = 15, method = "ward.D2")
react router v5 to v6 nested route not working
<Routes>
<Route
path="galleria"
element={<Gallery datas={data} clickEvent={handleSlideShow} />}
/>
<Route path="/galleria/:urlPath" element={<Paint datas={data} />} />
</Routes>
<div className="column nav-links">
<span className="prev-btn">
{prevSlide <= -1 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[prevSlide].urlPath}></Link>
)}
</span>
<span className="next-btn">
{nextSlide >= 15 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[nextSlide].urlPath}></Link>
)}
</span>
</div>
<Link
className="active"
to={`../${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`../${datas[nextSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[nextSlide].urlPath}`}
>
</Link>
-----------------------
<Routes>
<Route
path="galleria"
element={<Gallery datas={data} clickEvent={handleSlideShow} />}
/>
<Route path="/galleria/:urlPath" element={<Paint datas={data} />} />
</Routes>
<div className="column nav-links">
<span className="prev-btn">
{prevSlide <= -1 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[prevSlide].urlPath}></Link>
)}
</span>
<span className="next-btn">
{nextSlide >= 15 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[nextSlide].urlPath}></Link>
)}
</span>
</div>
<Link
className="active"
to={`../${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`../${datas[nextSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[nextSlide].urlPath}`}
>
</Link>
-----------------------
<Routes>
<Route
path="galleria"
element={<Gallery datas={data} clickEvent={handleSlideShow} />}
/>
<Route path="/galleria/:urlPath" element={<Paint datas={data} />} />
</Routes>
<div className="column nav-links">
<span className="prev-btn">
{prevSlide <= -1 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[prevSlide].urlPath}></Link>
)}
</span>
<span className="next-btn">
{nextSlide >= 15 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[nextSlide].urlPath}></Link>
)}
</span>
</div>
<Link
className="active"
to={`../${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`../${datas[nextSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[nextSlide].urlPath}`}
>
</Link>
-----------------------
<Routes>
<Route
path="galleria"
element={<Gallery datas={data} clickEvent={handleSlideShow} />}
/>
<Route path="/galleria/:urlPath" element={<Paint datas={data} />} />
</Routes>
<div className="column nav-links">
<span className="prev-btn">
{prevSlide <= -1 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[prevSlide].urlPath}></Link>
)}
</span>
<span className="next-btn">
{nextSlide >= 15 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[nextSlide].urlPath}></Link>
)}
</span>
</div>
<Link
className="active"
to={`../${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`../${datas[nextSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[nextSlide].urlPath}`}
>
</Link>
-----------------------
<Routes>
<Route
path="galleria"
element={<Gallery datas={data} clickEvent={handleSlideShow} />}
/>
<Route path="/galleria/:urlPath" element={<Paint datas={data} />} />
</Routes>
<div className="column nav-links">
<span className="prev-btn">
{prevSlide <= -1 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[prevSlide].urlPath}></Link>
)}
</span>
<span className="next-btn">
{nextSlide >= 15 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[nextSlide].urlPath}></Link>
)}
</span>
</div>
<Link
className="active"
to={`../${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`../${datas[nextSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[nextSlide].urlPath}`}
>
</Link>
-----------------------
<Routes>
<Route
path="galleria"
element={<Gallery datas={data} clickEvent={handleSlideShow} />}
/>
<Route path="/galleria/:urlPath" element={<Paint datas={data} />} />
</Routes>
<div className="column nav-links">
<span className="prev-btn">
{prevSlide <= -1 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[prevSlide].urlPath}></Link>
)}
</span>
<span className="next-btn">
{nextSlide >= 15 ? (
<span className="disable"></span>
) : (
<Link className="active" to={datas[nextSlide].urlPath}></Link>
)}
</span>
</div>
<Link
className="active"
to={`../${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`../${datas[nextSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[prevSlide].urlPath}`}
>
</Link>
<Link
className="active"
to={`/galleria/${datas[nextSlide].urlPath}`}
>
</Link>
QUESTION
R - dplyr- Reducing data package 'storms'
Asked 2022-Apr-15 at 11:08I am working with dplyr and the data package 'storms'.
I need a table in which I have each measured storm in a column. Then I want to give each row an ID.
So far I have
storm_ID <- storms %>%
select(year,month,name) %>%
group_by(year,month,name) %>%
summarise(ID = n())
storm_ID
View(storm_ID)
The only thing is that it doesn't do anything for me.
I don't quite understand how I can see every single storm in the table. I had previously sorted them by name. Then I get 214 storms. However, storms with the same name occur in several years.
At the end I want something like:
name | year | month | day | ID
| | | | |
Zeta 2005 12 31 Zeta1
Zeta 2006 1 1 Zeta1
| | | | |
Zeta 2020 10 24 Zeta2
To do this, I need to know if a storm occurred in 2 years (i.e. from 2005-12-31 to 2006-01-01) But this should then only be counted as one storm.
After that I should then be able to evaluate the duration, wind speed difference and pressure difference per storm. What I had already evaluated with the wrong sorting.
Help would be nice.
Thanks in advance.
ANSWER
Answered 2022-Apr-15 at 09:37For you first problem:
storm_ID <- storms %>%
select(year,month,name) %>%
group_by(year,month,name) %>%
mutate(ID = stringr::str_c(name, cur_group_id()))
This create a unique Storm-Name-ID, e.g. Amy1, Amy2 etc.
This is how you can check if a storm has happened in consecutive years
storms %>%
group_by(name) %>%
mutate(consec_helper = cumsum(c(1, diff(year) != 1))) %>%
group_by(name, consec_helper) %>%
filter(n() > 1)
I find this to be true only for Zeta
name year
<chr> <dbl>
1 Zeta 2005
2 Zeta 2006
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit