Useful R codes

How to get min and max value and the associated year that min and max values occurred previous <- dfile %>%filter(YearLabel == "Previous") %>%group_by(MonthName) %>%summarize(min_extent = min(extent_mil),max_extent = max(extent_mil),year_min =…

Creating htmlwidget in RStudio

To set up required packages to create htmlwidget install.packages("htmlwidgets") install.packages("devtools") Scaffolding will provide a template (basic structure) for a widget development library(devtools) create("my_widget") htmlwidgets::scaffoldWidget("my_widget") document() # Update documentation build() #…

R data wrangling

This code snippet has nice examples of data wrangling From https://www.jumpingrivers.com/blog/r-d3-intro-r2d3/ scoobydoo = tuesdata$scoobydoo # wrangling data into nice shape monsters_caught = scoobydoo %>% select(date_aired, starts_with("caught")) %>% mutate(across(starts_with("caught"), ~ as.logical(.)))…

Ways to download ERDDAP Data using python

ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE url = 'https://oceanwatch.pifsc.noaa.gov/erddap/griddap/sw_chla_monthly_2018_0.nc?chlor_a[(1997-10-16T12:00:00Z):1:(2010-10-16T12:00:00Z)][(25):10:(15)][(198):10:(208)]' file_name = "sw.nc" with urllib.request.urlopen(url, context=ctx) as u, \ open(file_name, 'wb') as f: f.write(u.read()) print('complete') source: https://github.com/CoastWatch-WestCoast/python_code/blob/satellite_course_jan_2022/compare_satellite_timeseries.ipynb def…

Spicy Cold Noodle

This is Spicy cold noodle recipe. You can use any noodle you like. I prefer chewy noodle like potato starch noodle (냉면). Ingredients noodle, apple (1), onion (optional), soy sauce,…