Original link: HTTP://WWW.DATASTUDY.CC/TO/13
Most of the time, the data we get is a aggregated piece of data, such as the data in our example, that has aggregated all the warehouse data. But when we're modeling, how do we do layered processing if we want to split them up? It's actually very simple, we can use the Split function. Split (x, F, drop = FALSE, ...) Let's look at the case of layered processing: Data Please download from Baidu disk: Link: http://pan.baidu.com/s/1kFxoy Password: TNBF data <-read.csv ("D: \\data\\20150922\\data.csv ", fileencoding=" UTF8 ", Stringsasfactors=false) datas <-split (data, data$ warehouse) Result < -C (); for (d in Datas) {#这里执行我们需要的建模, #我这里演示就用了个计算平均数m <-mean (d$ price); #把建模后的模型加入到结果数组中result <-append (result, m)} result These are the most basic models of layered processing, including the layering of data, and the assembly of processed results into a vector return.
How to layer data by a column