Skip to content
Prev 349961 / 398513 Next

help assigning values to matrix

Hi group,
 
I am automatically creating several matrices to store results from different analyses on vectors of different lengths. The matrices are named according  to each vector, so I can trace back results. I am using the following commands, which give me an error. My idea is to populate the for loop to include several steps and keep adding results to the matrices. But to start with:
[1] "PS013_1" "PS056_1" "PS058_1" "PS080_1" "PS117_1" "PS193_1" "PS194_1"
#create as many 13x3 matrices as vectors I have. The rowname of the last row will be the length of the vector
# Example: assign three values in the last row of the created matrices
}
 
Error in paste("results", mynames[j], "1", sep = "_")[13, ] : 
  incorrect number of dimensions
 
 
I have noticed that to access the positions of a matrix I cannot use [row,column] coordinates, but actual "count" positions like:
 
#let's write something  in one of the matrices, since they are all NAs
col1 col2     col3      
10  1 14 27
20  NA     NA      NA       
30  NA     NA      NA       
35  NA     NA      NA       
40  NA     NA      NA       
50  NA     NA      NA       
60  NA     NA      NA       
70  NA     NA      NA       
80  NA     NA      NA       
90  NA     NA      NA       
100 NA     NA      NA       
120 NA     NA      NA       
295 NA     NA      NA
[1] 1
[1] NA
[1] 14
[1] 1    14   27
 
So if I try to write three other values to the first row of the first matrix, I now try the following
Error in assign(get(paste("results", mynames[1], "1", sep = "_"))[c(1,  : 
  invalid first argument

 
Can anyone explain to me why I cannot assign the values in this way and how is it that I cannot use [row,column] coordinates?
 
Thanks in advance for your help
 
Dave