Articles by Xianjun Dong

match vs. %in%

November 4, 2011 | Xianjun Dong

match and %in% are two very commonly-used function in R. So, what's the difference of them?First, how to use them -- (copy from R manual)match returns a vector of the positions of (first) matches of its first argument in its second.%in% is a ... [Read more...]

single-column data frame

October 10, 2011 | Xianjun Dong

This is a trivial but very useful tip:__ x=data.frame(a=1:4, c=5)__ x a c1 1 52 2 53 3 54 4 5__ x[1,] a c1 1 5__ x[,1][1] 1 2 3 4__ x[,1, drop=F] a1 12 23 34 4where you can see that:to avoid a[, i] become a vector, rather than a... [Read more...]

DTW: dynamic time warping 动态时间规整

September 18, 2011 | Xianjun Dong

Basically, DTW (dynamic time warping) is an algorithm to output cumulative distance of two time sequences, which is widely used e.g. for classification and clustering.For example, when using k-mean for clustering, we can use DTW as distance function. Here is one of such nice instances (using R: http://... [Read more...]

Density curve of histogram plot in R

September 1, 2011 | Xianjun Dong

Ref: http://casoilresource.lawr.ucdavis.edu/drupal/book/export/html/23 To add density curve on a histogram, like the green curve above, use code below:#plot the distributionhist(slope, breaks=1000, freq=F, main=main, xlab="Slope Value (percent)", ... [Read more...]

Add text aligned to legend in R plot

September 1, 2011 | Xianjun Dong

What I meant is to add text on a R plot when there is already legend on it. Like the left plot in above figure, another piece of text was put exactly below the legend "Pearson'r ...RMSE = 1.9". Here is the code for that: l=legend("topleft", paste(... [Read more...]
1 2 3

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)