由买买提看人间百态

topics

全部话题 - 话题: nrows
1 2 3 下页 末页 (共3页)
i**********e
发帖数: 1145
1
来自主题: JobHunting版 - 新鲜onsite面经
我写的 boggle 游戏算法,DFS + trie.
一秒以内给出所有 5x5 的答案。
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct Trie {
bool end;
Trie *children[26];
Trie() {
end = false;
memset(children, NULL, sizeof(children));
}
void insert(const char *word) {
const char *s = word;
Trie *p = this;
while (*s) {
int j = *s-'A';
assert(0 <= j && j < 26);
if (!p->childre... 阅读全帖
A*******e
发帖数: 2419
2
来自主题: JobHunting版 - LC的难度级别怎么定的?
写了一个zigzag,通过了测试,但运行时间在C++里算慢的,相当于C#的水平。谁有更
简洁的
解法?index计算太容易错了,必须在纸上分析清楚才行。
class Solution {
public:
string convert(string s, int nRows) {
if (nRows == 1) {
return s;
}
vector char_rank;
for (int i = 0; i < s.size(); ++i) {
char_rank.push_back({s[i], GetNewIndex(i, nRows)});
}
sort(char_rank.begin(), char_rank.end(), CharRankComp());

string result;
for (const auto& it : char_rank) {
... 阅读全帖
M**********s
发帖数: 8
3
来自主题: JobHunting版 - twitter 一题

注意
1.Up[0]+...Up[i-1] == Down[i+1]+...Down[n-1]只与i相关
2.Left[0]+..Left[j-1] == Left[j+1]...Left[m-1]只与j相关
故1式成立时,称i行为平衡行
当2式成立时,称j行为平衡列
行列的关系彼此独立,故平衡数总个数=平衡行数*平衡列数
剩下就是一些实作细节问题
其实只要记住每行每列和,在迴圈中就可判断是否为平衡行列了
下面是O(m+n) space, O(m*n) time的实作
其实还满简单的,只是稍长了些
int balancingCells(vector >& matrix) {
if (matrix.empty()) return 0;
int nRow = matrix.size(), nCol = matrix[0].size();
vector rowSum(nRow, 0), colSum(nCol, 0);
int total = 0;
for (int r=0; r for (int c=... 阅读全帖
M**********s
发帖数: 8
4
来自主题: JobHunting版 - 这个题用四维DP怎么做呢?
以下讨论都先设m==n,也就是资料为方阵,complexity写起来比较简单
如果非方阵的话设N=max(m, n),big O还是对的
这题细节满多
我原本以为自己可以一次写对O(N^3)的解,但OJ发现有错
建议觉得自己能一次写对的人都试着自己写写看 http://soj.me/1767

四维DP的time complexity O(N^4)显然可以更好
如同前面说的三维可以达到time complexity O(N^3)
这题就是同时歸划两条左上角到右下角的不重疊路线,并最大化得分
要訣是每次同时考虑两条路线的同一步
设d为离左上角的曼哈頓距离
d=1第一步,考虑(0, 1), (1, 0)
只能选左线(0, 1)右线(1, 0)
d=2时一步,考虑(0, 2), (1, 1), (2, 0)
有左(0, 2)右(1, 1)、左(0, 2)右(2, 0)、左(1, 1)右(2, 0)三种选择
可以定义DP表dp[d][c1][c2]为
考虑左线进行到(r1, c1),右线进行到(r2, c2)时的最大得分
r1 = d - c1, r2 = d - c2
这也是前面有人提到用对... 阅读全帖
p****e
发帖数: 3548
5
string convert(string s, int nRows) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(nRows <= 1) return s;
int size = s.length();
if(size <=nRows) return s;
int direction = 1;
int row = 0;
int period = 2*nRows-2;
string * ret = new string[nRows];
for(int i = 0; i < size; i++)
{
ret[row].push_back(s[i]);
int modi = i%period;
if(modi =... 阅读全帖
r********g
发帖数: 1351
6
来自主题: JobHunting版 - request solutions to 2 questions on leetcode
写了一个,可能有点罗嗦。。
class Solution {
public:
void setZeroes(vector > &M) {
// Start typing your C/C++ solution below
// DO NOT write int main() function

int nRow = M.size();
if(nRow <= 0) return;
int nCol = M[0].size();
if(nCol <= 0) return;

bool rowZero = false;
bool colZero = false;
for(int i = 0; i < nRow; i++) if(!M[i][0]) colZero = true;
for(int j = 0; j < nCol; j++) if(!M[0][j]) rowZer... 阅读全帖
r********g
发帖数: 1351
7
来自主题: JobHunting版 - request solutions to 2 questions on leetcode
写了一个,可能有点罗嗦。。
class Solution {
public:
void setZeroes(vector > &M) {
// Start typing your C/C++ solution below
// DO NOT write int main() function

int nRow = M.size();
if(nRow <= 0) return;
int nCol = M[0].size();
if(nCol <= 0) return;

bool rowZero = false;
bool colZero = false;
for(int i = 0; i < nRow; i++) if(!M[i][0]) colZero = true;
for(int j = 0; j < nCol; j++) if(!M[0][j]) rowZer... 阅读全帖
i****d
发帖数: 255
8
来自主题: Computation版 - Fotran77程序的移植问题
Depending on the compiler, the definition of an array like
COMPLEX TUINV(NROWS,NROWS),TDLDA(NROWS)
with NROWS passed by COMMON, is problematic. Just think
of what happens if NROWS is modified in your subroutine.
Add NROWS to the arguments of the subroutine.




t*****w
发帖数: 254
9
来自主题: Statistics版 - 请问面试 R 应该怎么准备?
When I had my job interview, they always tested my SAS skill.However I use R
all the time. To help your preparation, read my R codes to see how much you
can understand it.
%in%
?keyword
a<-matrix(0,nrow=3,ncol=3,byrow=T)
a1 <- a1/(t(a1)%*%spooled%*%a1)^.5 #standadization in discrim
a1<- a>=2; a[a1]
abline(h = -1:5, v = -2:3, col = "lightgray", lty=3)
abline(h=0, v=0, col = "gray60")
abs(r2[i])>r0
aggregate(iris[,1:4], list(iris$Species), mean)
AND: &; OR: |; NOT: !
anova(lm(data1[,3]~data1[,1... 阅读全帖
B********t
发帖数: 147
10
小弟的代码在此,能通过small的test,但是large时说memory limit exceeded,难道
这题还能in place不成?
class Solution {
public:
string convert(string s, int nRows) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(nRows == 1)
return s;
int circle = 2*nRows - 2;
string ret;
for(int i = 0; i < nRows; i++)
{
int j = i;
while(j < s.size())
{
ret.push_back(s[j]);
... 阅读全帖
y***n
发帖数: 1594
11
看了几个人家写的答案,都不是很明白。比如这个。 有么有高手帮忙解释一下。
string convert(string s, int nRows) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(nRows <= 1) return s;
string ret;
int zigsize = 2 * nRows - 2;
for(int i = 0; i < nRows; ++i) {
for(int base = i; base cout<<"base - "< ret.append(1,s[base]);
if(i > 0 && i < nRows - 1) { /... 阅读全帖
y***n
发帖数: 1594
12
看了几个人家写的答案,都不是很明白。比如这个。 有么有高手帮忙解释一下。
string convert(string s, int nRows) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(nRows <= 1) return s;
string ret;
int zigsize = 2 * nRows - 2;
for(int i = 0; i < nRows; ++i) {
for(int base = i; base cout<<"base - "< ret.append(1,s[base]);
if(i > 0 && i < nRows - 1) { /... 阅读全帖
b********e
发帖数: 109
13
来自主题: Computation版 - Fotran77程序的移植问题
我在Fortran PowerStation 4 下使用一个程序,发现不能debug,可以设置断点,但是程
序并不停。于是考虑移植到Visaul Fortran 6.6下,发现可以调试,也可以编译通过,但
是执行是却遇到stack overflow的问题,后来发现是一个子程序的数组定义有问题,但是
在Powerstation4 下却可以执行。那个子程序数组定义如下:
SUBROUTINE GHMAT7(NE,CONE,TUINV,TDLDA)
COMPLEX TUINV(NROWS,NROWS),TDLDA(NROWS)
INTEGER CONE(NE,4),VB_ID
COMMON N,NP,INP,IPR,ITX
COMMON /GEOMET/NROWS,NCOLM
结果发现程序运行到第一行和第二行是均发现溢出,为什么Powerstation中可以通过运
行呢?
BTW, NROWS值为600。
t*****w
发帖数: 254
14
来自主题: Statistics版 - 怎样来选这些dyads
answer is the following;
your final result is the following:
student teacher senior
2732 3465 1
3347 3837 1
1179 1693 1
3875 1711 1
3875 2059 1
2032 1784 1
2848 3921 1
2148 1416 1
3038 1434 1
3530 2037 1
2585 3811 1
1481 3954 1
... 阅读全帖
f*****y
发帖数: 124
15
来自主题: Software版 - 求助:excel 删除行数据问题
如果你会自己录制宏,录个空的宏,把下面代码加进去。
Sub DelRows()
'
' Delete Rows in Excel , Macro
'
'
Dim InitialRow(), nRow
InitialRow = Array(10, 100, 240) 'Edit or Add here
For Each nRow In InitialRow
Rows(nRow & ":" & nRow + 19).Select
Selection.Delete Shift:=xlUp
Next
End Sub
B*******e
发帖数: 3882
16
来自主题: Software版 - 求助:excel 删除行数据问题
你在 Rows 前面加上 ActiveSheet. 试试。也就是改成(Fishboy 的code 应该也是这个
问题):
Sub DelRows()
'
' Delete Rows in Excel , Macro
Dim InitialRow(), nRow
Dim DelRange As Range
InitialRow = Array(240, 100, 10) 'Edit or Add here
Set DelRange = ActiveSheet.Rows(InitialRow(0))
For Each nRow In InitialRow
Set DelRange = Union(DelRange, Range(ActiveSheet.Rows(nRow), ActiveS
heet.Rows(nRow + 19)))
Next
DelRange.Select
Selection.Delete Shift:=xlUp
End Sub
t*****w
发帖数: 254
17
来自主题: Statistics版 - 怎样来选这些dyads
your final result is the following:
[,1] [,2]
[1,] 1337 1693
[2,] 3768 3793
[3,] 3530 1416
[4,] 3607 1711
[5,] 2732 3465
[6,] 2732 3811
[7,] 3347 3837
[8,] 1292 3954
[9,] 3254 1784
[10,] 3254 3921
[11,] 3422 1434
[12,] 2148 2037
[13,] 3875 2059
[14,] 2762 1109
r codes are the following :
x<- scan("")
3347 1109
2762 1109
2148 1416
3530 1416
3457 1416
3038 1434
3422 1434
1337 1693
1179 1693
3875 1711
3607 1711
3212 1711
3254 1784
2032 1784
3415 17... 阅读全帖
n*****3
发帖数: 1584
18
来自主题: DataSciences版 - 问一道(大)数据 algorithm (转载)
你说的对, 这不是大数据。
因为在modeling training stage, 用 R 跑prototype system,
R itself 不 方便 并行。 下一阶段 会上 spark/hadoop。
继续 抛砖引玉一下。 下面的 CPP file 跑得还行。 用 sourceRCPP call
就可。 看看有什么可以改进的,
再次 谢谢大家 all
#include
using namespace Rcpp;
using namespace std;
// Below is a the balancing C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp
// function (or via the Source button on the editor toolbar)
// For more on using Rcpp click the Help button on the editor toolbar
// [... 阅读全帖
a******e
发帖数: 124
19
来自主题: JobHunting版 - 问一个C++ delete 节点的问题
可以在main函数里delete掉,或者建一个新的function专门delete dynamically
located pointer吧.
如下例
http://www.codeproject.com/Articles/21909/Introduction-to-dynam
template
T **AllocateDynamicArray( int nRows, int nCols)
{
T **dynamicArray;
dynamicArray = new T*[nRows];
for( int i = 0 ; i < nRows ; i++ )
dynamicArray[i] = new T [nCols];
return dynamicArray;
}
template
void FreeDynamicArray(T** dArray)
{
delete [] *dArray;
delete [] dArray;
}
int main()... 阅读全帖
d*******o
发帖数: 5897
20
来自主题: Programming版 - c++读写多个大文件的问题
在linux下面。有几百个text输入文件,每个文件2GB,每个文件里包含一个double 矩
阵,大概几千万个elements吧,每个文件的矩阵行数相等、列数也相等,假设行数为
NRow,列数为NCol吧。
要对每个输入文件的每个elements做些计算,这些计算有下面这些特点/约束:
1. 同一个输入文件里,不同行、列号的element是互相独立的,即对某一element的计
算不需另一个element的信息;
2. 不同文件里,行号、列号分别相等的element,它们是有关系的。如果把几百个文件
排序,对一个文件里的一个element的计算,需要用到前面的文件里行号、列号分别相
等的element的信息;
3. 对同一输入文件的所有(NRow * NCol个)element计算后,因为每个element对应一
个输出element,所以会有总共NRow * NCol个输出element,这些输出element都在一个
输出文件里;
4. 最后输出文件数目和输入文件数目相等,每个输出文件也包含一个和输入文件同样
大小的矩阵
这么大的数据量,不可能一次全读进内存,所以只能分次读;因为... 阅读全帖
k**********g
发帖数: 989
21
Depends on how big the area is.
More precisely, what is the maximum distance from the set of missing pixels
to the nearest valid pixel.
The general technique is called Infilling.
Here's just an example from Google search result. http://research.microsoft.com/pubs/67276/criminisi_tip2004.pdf
When the text is very thin, a masked local averaging will do the job.
img = imread( filename ) ;
[ nrows, ncols, nchan ] = size ( img ) ;
imgColor = double ( img ) .* (1 / 255) ;
imgGray = rgb2gray ( imgColor... 阅读全帖
p***r
发帖数: 4859
22
来自主题: Software版 - 求助:excel 删除行数据问题
Sub DelExcelRow(nRow As Long)
Rows(nRow & ":" & nRow).Select
Selection.Delete Shift:=xlUp
End Sub
Sub test()
DelExcelRow 4
End Sub

119
B*******e
发帖数: 3882
23
来自主题: Software版 - 求助:excel 删除行数据问题
You have to consider that the row numbers will change after you delete the r
ows in the first round of the loop.
Here is my code:
Sub DelRows()
'
' Delete Rows in Excel , Macro
'
'
Dim InitialRow(), nRow
Dim DelRange As Range
InitialRow = Array(10, 100, 140) 'Edit or Add here
Set DelRange = Rows(InitialRow(0))
For Each nRow In InitialRow
Set DelRange = Application.Union(DelRange, Range(Rows(nRow), Rows(nR
ow + 19)))
Next
DelRange.Select
Selection.Dele
D******n
发帖数: 2836
24
来自主题: Statistics版 - a R loop question
This is definitely worth some baozis...
kf=c(0,1,0,0,0,1,1,0,0,0,0,0)
kf=matrix(kf,3)
nrow <- nrow(kf);
ncol <- ncol(kf);
oripos <- which(t(kf)==1,arr.ind=T)[,1];
nowpos <- oripos;
rowptr <- 1;
cat(nowpos,'\n');
while (rowptr<=nrow)
{
if ( nowpos[rowptr] { nowpos[rowptr] = nowpos[rowptr]+1;
rowptr = 1;
cat(nowpos,'\n');
}
else {
nowpos[rowptr] = oripos[rowptr];
rowptr = rowptr + 1;
}
}
y********i
发帖数: 205
25
我最近写了个如下的code,原来的code在definition部分有点问题,所以就把
definition的部分改了下。改之前t值的变化会影响结果的变化,但是我做了一点改动
之后,无论如何改动t值,结果都不变了,而且即使把t删掉,结果也不变。不知道是什
么原因?每次运行,log里都显示没有问题。但是如果把t值设置成0,结果会报错,不
知道有高人能指点下或大致判断下原因不?
proc iml;
/* Used for debugging only */
*reset log print details;
start COptimal(xx)
global (Weight, Var1, b0, b1, b2, t);
/* nrow(xx)=1, ncol(xx)=Nd*2 */
x=shape(xx,nrow(xx)*ncol(xx)/2,2);

F=j(nrow(x),1) || x[,1] || x[
g**r
发帖数: 425
26
来自主题: Statistics版 - 这个R程序能帮改进一下吗?
我的DATA:
a=matrix(c(3,4,5,6,7,6),nrow=2,byrow=TRUE)
我想要的结果:
b=matrix(0,nrow=2,ncol=10)
for(i in 1:nrow(a))for(j in 1:ncol(a))
b[i,a[i,j]]=1+b[i,a[i,j]]
但觉得我的这个方法也太土了。R玩的不熟,大家帮忙。
S******y
发帖数: 1123
27
最近在研究R - biglm.
R document 里说 - "biglm creates a linear model object that uses only p^2
memory for p variables. It can be updated with more data using update. This
allows linear regression on data sets larger than memory."
读了下面的 source code, 还是没搞懂update具体是怎么实现的。。。
> biglm::biglm
function (formula, data, weights = NULL, sandwich = FALSE)
{
tt <- terms(formula)
if (!is.null(weights)) {
if (!inherits(weights, "formula"))
stop("`weights' must be a formula")
w <- ... 阅读全帖
f***a
发帖数: 329
28
来自主题: Statistics版 - 问个面试问题
回来了回来了。
重新想了下,这个其实就是在一堆iid variables之间加了一个constraint。貌似
sample起来不难。
以最简单的n=2,m=1为例:
Without constraint, outputs space is {(0,0),(0,1),(1,0),(1,1)}.
The corresponding probability space is {(1-p1)*(1-p2), ..., p1*p2}.
With constraint, outputs space is O={(0,1),(1,0)}.
The corresponding probability space is P={(1-p1)*(p2), p1*(1-p2)}.
Under the constrain, standardize the probability space into
P.std={P1/(P1+P2),P2/(P1+P2)}.
Then under constrain, output (0,1) has the probability P1/(P1+P2) to be
sam... 阅读全帖
f***a
发帖数: 329
29
来自主题: Statistics版 - 问个面试问题
回来了回来了。
重新想了下,这个其实就是在一堆iid variables之间加了一个constraint。貌似
sample起来不难。
以最简单的n=2,m=1为例:
Without constraint, outputs space is {(0,0),(0,1),(1,0),(1,1)}.
The corresponding probability space is {(1-p1)*(1-p2), ..., p1*p2}.
With constraint, outputs space is O={(0,1),(1,0)}.
The corresponding probability space is P={(1-p1)*(p2), p1*(1-p2)}.
Under the constrain, standardize the probability space into
P.std={P1/(P1+P2),P2/(P1+P2)}.
Then under constrain, output (0,1) has the probability P1/(P1+P2) to be
sam... 阅读全帖
W***Y
发帖数: 27
30
来自主题: Statistics版 - 请教R Code, 多谢!
我想把一个6*4 的matrix 里的每一行的四个数,重新组成一个2*2 matrix , (就是
第一和第二个数作为新的2*2 matrix 里的第一行,第3和4 个数,做第二行,然后,把
每个2*2 matrix 用fisher.test, 算出P-value, 再把所有P-value 按大小排序。
我自己的 code 如下,但是,只计算最后一行的。 请教,问题在哪里?帮我修改一下
吧。
多谢了
rm(list=ls())
fly <- read.table( "fly-7.txt",header=T)
names(fly)
rownames(fly) <- paste( "Gene", 1:nrow(fly), sep="_" )
fly <- as.matrix( fly)
n=nrow(fly)
res=matrix(0,nrow=n, ncol=1,byrow="T")
i<-c(1:n)
for(i in 1:n){
x_i<-as.numeric(fly[i,])
(x_i_12=c(x_i[1],x_i[2]))
(y_i_34=c(x_i[3],x_i[4]))
x... 阅读全帖
p********y
发帖数: 15
31
来自主题: Statistics版 - 请教大神们关于bootstrap
mat=matrix(0,ncol=100000,nrow=nrow(OTU_matrix))
i=0
while (i<=100000){
new=sample(OTU_matrix[,1],nrow(OTU_matrix),replace=T)
if (sum(new)==4190){
mat[,i]=new
i=i+1
}
}
OTU_matrix每列是我要抽的样本,mat是我要生成的resampling data
i**********e
发帖数: 1145
32
不用binary search,从右上或者左下角开始.
右上角:
每次走左一步(如果target数字小于此数字)或走下一步(如果target大于此数字);
如果等于则返回true。
worst case nRows + nCols 完成。
有人已经证明不可能比 O(nRows + nCols) 更好:
http://www.quora.com/You-are-given-an-MxN-matrix-of-numbers-wit
b****5
发帖数: 449
33
部分截图吧
for (i in 1:Lindex){
newPriceMatrix[,i]=price[,index[i]]
newMDY[i]= mdy[index[i]]
newDates[i]=dates[index[i]]
}
newMDY = as.numeric(newMDY)
newDates = as.Date(newDates,origin='1970-01-01')
maxDropsTickers=data.frame(matrix(rep(0,nPick*length(index)),nrow=nPick))
maxRisesTickers=data.frame(matrix(rep(0,nPick*length(index)),nrow=nPick))
我自己以前写过不少这种点子,比如连续跌N天买入,买52week high,momentum,mean
-reversion很多策略。和你们说下吧。
连跌N天买入,52 week high,卵用都没有。
有用的是啥?SP500的非能源股票,其他啥都可以,在跌到52 week low以后如果
volat... 阅读全帖
w****e
发帖数: 1883
34
啥狗屁程序?

:部分截图吧
:for (i in 1:Lindex){
: newPriceMatrix[,i]=price[,index[i]]
: newMDY[i]= mdy[index[i]]
: newDates[i]=dates[index[i]]
:}
:newMDY = as.numeric(newMDY)
:newDates = as.Date(newDates,origin='1970-01-01')
:maxDropsTickers=data.frame(matrix(rep(0,nPick*length(index)),nrow=nPick))
:maxRisesTickers=data.frame(matrix(rep(0,nPick*length(index)),nrow=nPick))
:..........
n******7
发帖数: 12463
35
来自主题: Linux版 - 请教一个打印列的问题
用awk算列数不划算,而且可能出错,如果每一行都有空白列的话,换成grep好点吧...
---
只会用shell基本功能,蛋疼的写了一下,觉得这样搞还不如用perl/python了...
#ncol=`awk '{print NF}' $1 | sort -r | head -1`
ncol=`head -1 $1 | grep -o $'\t' | wc -l`
ncol=$((ncol+1))
nrow=`wc -l $1| cut -f 1 -d ' ' `
good_cols=()
for ((i=1;i<=$ncol;i++))
do
non_blank=`cut -f $i $1 | grep -v '^$' |wc -l | cut -f 1 -d ' '`
if (( $(echo "$non_blank == $nrow" | bc -l) ))
then
good_cols=("${good_cols[@]}" $i)
fi
done
SAVE_IFS=$IFS
IFS=","
cols="${good_cols[*]... 阅读全帖
G***G
发帖数: 16778
36
来自主题: Programming版 - matlab取行数
how to get the total number of rows in a matrix in MATLAB
for example,
A=[1 2 3;
4 5 6;
7 8 9];
[nrow,ncol]=size(A);
Is there other command which can return only nrow not ncol?
o********7
发帖数: 154
37
来自主题: Programming版 - 这个怎么allocate memory?
有一个integer 2D array, column是2列, row的数目不确定, 是从function的参数传
过来的,大小是nrows, 这个array大概的样子就是 myArray[][2]
如何在C中allocate memory呢?我用了下面的编译不过
int (*myArray)[2] = malloc(nrows*sizeof(int[2]));
a***y
发帖数: 2803
38
来自主题: Programming版 - 这个怎么allocate memory?
int** myArray;
myArray = (int**) malloc(nrows * sizeof(int*));
for (int i = 0; i < nrows; i++)
myArray[i] = (int*) malloc(2 * sizeof(int));
s********y
发帖数: 64
39
来自主题: Programming版 - 问个关于R的低级问题
以下程序在执行opt <- yahoo.getAllOptions("IBM")后可以把IBM的option数据下载到
temporary file, 请问如何把temporary file的数据导出到一个TXT文件?
谢谢!
------------------------------------------------------------------
require(fCalendar)
require(fredImport)
## workaround for R 2.1.1:
Sys.timezone <- function ()
as.vector(Sys.getenv("TZ"))
yahoo.getOption <- function(ticker="QQQQ",maturity="2005-12",file="
tempfile01",method="internal",get.short.rate=TRUE) {
############################################################################... 阅读全帖
h**h
发帖数: 7
40
来自主题: Software版 - 求助:excel 删除行数据问题
运行这段代码出错:Rows(nRow & ":" & nRow + 19).Select。从后向前删除数据。请
问如何解决?
l**********1
发帖数: 5204
41
Continue:
第四乐章 Finale
找有关的PhD dissertation 里边的 R source code program
while U can debug it or even rewrite it for another task,
then you already masted NGS coding skills.
比如
http://www.dspace.cam.ac.uk/handle/1810/218542
DSpace at Cambridge
title: Genome-wide analyses using bead-based microarrays
Authors: Dunning, Mark J
Issue Date: 4-Sep-2008
Files in This Item:
File Description Size Format
dunning_thesis_.pdf 10.47 MB Adobe PDF
its Appendix B
R source Code f... 阅读全帖
g****y
发帖数: 199
42
☆─────────────────────────────────────☆
walp (暂无) 于 (Thu Jul 10 01:05:02 2008) 提到:
用下面的语句生成一个30×30的矩阵,写成matrixA.dat文件
% generate a matrix
A = delsq(numgrid('C',8));
[nrow,ncol]=size(A);
% write the matrix to a .dat file
fid=fopen('matrixA.dat','w');
for i=1:nrow
for j=1:ncol
count=fwrite(fid, A(i,j),'double');
end
end
fclose('all');
这样一个简单的文件怎么在fortran77里读进来?我试了好多次open和read的参数都不
行,错误好几种,或者"formatted I/O on unformatted unit", 或者"record is too
long" 等等。
我不太熟悉fortran77的输入输出,自己试
k*******d
发帖数: 1340
43
3. 我觉得他在问Volatility smile. Hull书上有,那个distribution不是严格log
normal的,在K大的地方,tail比Log normal小,K小的地方,tail大,这个是equity
option。foreign currency option是两边都是fat tail
7.
int** Darray = new int*[nRow];
for (int i = 0; i Darray[i] = new int[nCol];
int a[3][4] is not dynamic.

?
it'
h****s
发帖数: 16779
44
来自主题: Statistics版 - SAS问题请教
这样应该行了:
proc iml;
use data;
read all var {ID} into ID;
read all var {AA} into AA;
read all var {Trt} into Trt;
close data;
ID_Trt1_AA3 = ID[loc(AA = 3 & Trt = 1)];
Num_ID_Trt1_AA3_unique = nrow(unique(ID_Trt1_AA3)) * ncol(unique(ID_Trt1_AA3
));
Num_Trt1 = nrow(Trt = 1) * ncol(Trt = 1);
print Num_ID_Trt1_AA3_unique Num_Trt1;
quit;
手头没SAS,不过大约就是这样。想要你的输出格式需要再控制输出流。
y****2
发帖数: 34
45
来自主题: Statistics版 - R 问题
We can do it as following example:
list1 <- list(matrix(1:9, nrow=3), matrix(10:18, nrow=3))
list2 <- list(2,3)
listnew <- mapply(subset, list1, select=c(-2,-3),SIMPLIFY = F)
Have fun.
y****2
发帖数: 34
46
来自主题: Statistics版 - R question
y <- matrix(c(1,2,3,4,1,3,2,5,1,2,3,5,2,3,4,1), nrow=4)
x <- c(1,2,3)
temp <- matrix(match(y, x), nrow=4)
n <- ncol(temp)
index <- rep(0,n)
for(i in 1:n){
comp <- temp[1:length(x),i]== 1:length(x)
index[i] <- i*(sum(comp, na.rm=T)==length(x))
}
ynew <- y[,-index]
You may try this one. I am thinking that the for loop could be replaced by a
more efficient code. (You know, for loop might be slow for large data set)
x**7
发帖数: 341
47
来自主题: Statistics版 - R 求助
> n<- nrow(data)
> for (j in 1:n){
+ for(i in 1:10 ){
+ if ((!is.na(data[j,i])) & data[j,i]==1){
+ data[j,(i+1):10] <- NA }
+ }
+ }
Error in `*tmp*`[[j]] : subscript out of bounds
这里 nrow(data)=5000,不知道为什么有这个error?
如果设定 j in 1:10,就没有error,而j in 1:20,同样的error
s*****n
发帖数: 2174
48
来自主题: Statistics版 - 这个R程序能帮改进一下吗?
b <- matrix(0, nrow = 2, ncol = 10)
for (i in 1:nrow(a)){
temp <- tapply(a[i,], a[i, ], length)
b[i, as.numeric(names(temp))] <- temp
}
a***d
发帖数: 336
49
来自主题: Statistics版 - 新手请教proc IML里do loop的问题
需要在proc IML里用一个 1 到3000000的do loop。
每个loop里要给一个15000000*1的vector的几个element赋值。
跑一次要挺长时间。问题是这个loop是用来算loglikelihood的,
要被下面optimize的routine 反复的call。请教大家怎么能让
这个do loop快一些。
在R里有sapply之类可以替代for loop,算起来快无数倍,sas里有
sapply这样的function么?
code如下:
proc IML;
/* write the log-likelihood function*/
start LogLik(param) global (datain);
igrp = datain[,5];*datain[,5] is group id
X = datain[,1:4]; *datain[,1:4] are independent variables
expXb = exp(X*param);
uniqIgrp = unique(igrp)`;
sumExpXb = ... 阅读全帖
k*******a
发帖数: 772
50
比如楼主的例子可以直接用
plist <- lapply(1:10, function(x) {
set.seed(x)
smp <- Boston[sample(1:nrow(Boston), nrow(Boston), replace = TRUE), ]
glm <- glm(medv ~ ., data = smp)
predict(glm, Boston)
})
cbind函数应该输入一系列的vector,所以作用到plist, 因为他是list, 所以把它当
vector来了,最后就得到一列的data frame, 这个函数的argument是不定的,所以是
cbind(...)
do.call("cbind", plist)就是把 plist里面的每个element当作一个argument,所以相
当于 cbind(plist[[1]], plist[[2]],...)

塞?
1 2 3 下页 末页 (共3页)