Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

阶梯状的矩阵,每行数据的第一个空的地方补上1

在DolphinDB database中有如下矩阵:

m=take(1 2 3 4,12) join take(int(),4) join take(1 2 3 4,8) join take(int(),8) join 1 2 3 4 $ 12:3

>m
col1    col2    col3
1        
2        
3        
4        
1        1    
2        2    
3        3    
4        4    
1        1        1
2        2        2
3        3        3
4        4        4

现在想让每行数据的第一个空的地方补上1(即m的数据如下所示),有什么办法?

col1    col2    col3
1       1    
2       1    
3       1    
4       1    
1       1       1
2       2       1
3       3       1
4       4       1
1       1       1
2       2       2
3       3       3
4       4       4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
for(i in 0..(m.rows()-1)){
    for(j in 0..(m.cols()-1)){
        if(isNull(m[i,j])==true){
            m[i,j]=1
            break
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...