如何将列插入到model.matrix中

时间:2015-05-31 13:53:01

标签: r model.matrix

我想在model.matrix中插入两个变量,但我不知道该怎么做

long long factors(int N) {
    long long ans = 0;        // Result to return
    int nr = (int) sqrt(N);   // Highest possible value of the lower factor

    // Count factorisations (a,b) with a ∈ 2..√N
    for (int b = 2; b <= nr; b++) {
        if (N % b == 0) {    // If b | N ..
            ans += N/b - 1;  // .. then b*(N/b) = N, so count 1..(N/b - 1)
        } else {
            ans += N/b;      // .. count 1..N/b
        }
    }

    // Remaing steps of algorithm, optimised:
    // - Add N-1 for 1st column (1,1..(N-1)), giving total (a,b) with a ∈ 1..√N
    // - Double, to cover the reversed pairs (b,a) with a ∈ 1..√N, b ∈ √N..N
    // - Subtract nr² or nr²-1, for pairs counted twice
    int fix = N - nr * nr - 1;     // A correcting term, chosen to compare to 0
    if ( fix < 0) {                   // I.e. if nr² = N ..
        ans = (2*ans) + N + fix;      // .. ans = 2*(ans + N-1) - (nr² - 1)
    } else {
        ans = (2*ans) + N + fix - 1;  // .. ans = 2*(ans + N-1) - (nr²)
    }

    return ans; 
}

[1] 475 28

> k<-model.matrix(m2)
> dim(k)

0 个答案:

没有答案