pure R version of LDA-C