R 语言DataFrame 排序

Sort:
dd
<- data.frame(b = factor(c("Hi","Med","Hi","Low"), levels = c("Low","Med","Hi"), ordered = TRUE), x = c("A","D","A","C"), y = c(8,3,9,9), z = c(1,1,1,2))

sort by column z (descending) then by column b (ascending)
1).
dd[with(dd, order(-z, b)),]
2).
dd[ order(-dd[,4], dd[,1]),]

 REngine engine = REngine.GetInstanceFromID("RDotNet");
DataTable table = new DataTable();
engine.EagerEvaluate("myDataFrame <- data.frame('Order' =
c(1,2,3,4,5),'Name' = c('Bob', 'Ryan', 'Mel', 'Mark', 'Ali'))");
DataFrame dataset = engine.EagerEvaluate("myDataFrame").AsDataFrame();
dataGridView_DF.DataSource = dataset;

public enum IrisSpecies
{
   setosa = 1,
   versicolor = 2,
   virginica = 3,
}

[DataFrameRow]
public class IrisData
{
   [DataFrameColumn("Sepal.Length")]
   public double SepalLength { get; set; }
   [DataFrameColumn("Sepal.Width")]
   public double SepalWidth { get; set; }
   [DataFrameColumn("Petal.Length")]
   public double PetalLength { get; set; }
   [DataFrameColumn("Petal.Width")]
   public double PetalWidth { get; set; }
   [DataFrameColumn("Species")]
   public IrisSpecies Species { get; set; }
}

var iris = engine.Evaluate("iris").AsDataFrame();
foreach (var row in iris.GetRows<IrisData>())
{
   Console.WriteLine(row.Species);
}

posted on 2014-02-18 22:20  大Z  阅读(7501)  评论(0编辑  收藏  举报