R

Comparison: sort, order and arrange

vector (or factor)

(x <- swiss$Education[1:20])

[1] 12 9 5 7 15 7 7 8 7 13 6 12 7 12 5 2 8 28 20 9

sort the vector

sort(x)

[1] 2 5 5 6 7 7 7 7 7 8 8 9 9 12 12 12 13 15 20 28

partial sorting

sort(x, partial = c(10, 15))

[1] 2 5 5 7 7 7 7 6 7 8 8 9 9 12 12 12 13 28 20 15

Partial sorting in R is different with that in Wikipedia.

Comparison: transform, within and mutate

Here is another comparison between two basic functions transform and within, and a tidyverse function dplyr::mutate. They all can be used for data munipulation, adding a new column to a data.frame. head(mtcars)

mpg cyl disp hp drat wt qsec vs am gear carb

Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4

Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.

Comparison: subset and filter

A detailed introduction on subsetting is seen in Hadley Wickham’s Advanced R.

The three subsetting operators. The six types of subsetting. Important differences in behaviour for different objects (e.g., vectors, lists, factors, matrices, and data frames).

Benjamin on Stack Overflow answered the question 1 of the comparison between subset() and dplyr::filter().

They are, indeed, producing the same result, and they are very similar in concept.

From NCL to R

From the point of atmospheric science, NCL has certain natural advantages in dealing with self-described meteorological data formats, but R is improving significantly.

Unformated Binary

I have to say both NCL and R are not as good at reading/writing binary files as Fotran, though technically they are able to do the job.

Self-decribed Binary

NCL uses a single function addfile to handle all format (netCDF, HDF, GRIB, CCM, shapefile), while R requires additional packages.

Hello World

I used to blog a little bit on Blogger when I was in China. I have stopped blogging for a long time since the emergency of social networks. Looking back at what I wrote when I was a young college student, I couldn’t help but feel how different I am right now. I really hope I can start likeing writting things again, focusing on R & Data Science from a geoscience perspective.