I am working with series of data, say nrow=500 & ncol=300.
this is only for example:
V211 V212 V213 V214 V215 V216
[1,] 2.6088731 2.5531749 2.6017147 2.6124385 2.7156729 2.7897892
[2,] 1.4816736 0.9634576 0.9346004 0.9999343 -1.1096868 1.0848002
[3,] 1.1547304 -0.9052018 0.9036510 0.8504258 0.8382223 0.9237510
[4,] 1.0049771 0.9032115 0.8538077 -0.7911187 0.8244491 0.9172450
[5,] 0.9888954 0.8589149 0.7850069 0.6574331 0.7917890 0.7667152
[6,] -0.9577423 0.7662278 0.7767129 0.5639352 0.7559162 0.7118414
each column has positive and negative numbers. What i wanna do is to filter positive numbers of each column and write those numbers into new matrix.
What i have done:
- read .csv data as matrix "data"
- create new matrix "new" matrix(0,500,300)
Using loop
for (i in 1:300) {a=data[which(data[,i]>0)] new[,i]=print(a)}
Then problems came:
it shows only positions of the data instead of the data itself (example):
[,238] [,239] [,240] [,241] [,242] [,243] [,244] [,245] [,246]
[1,] 1 1 1 1 1 1 1 1 1
[2,] 2 2 2 2 2 2 2 2 2
[3,] 3 3 3 3 3 3 3 3 3
[4,] 4 4 4 4 4 4 4 4 4
[5,] 5 5 5 5 5 5 5 5 5
[6,] 6 6 6 6 6 6 6 6 6
i have been searching another possible solutions but what I've found mostly data with header on each column. Since i have a lot of series, it needs a long time to name them one by one.
Please leave me some advise! thanks
forloop is not the best tool here. - RolandNA? - Roland