matrix - How to search and extract values based on file names in R? -



matrix - How to search and extract values based on file names in R? -

i have matrix a contain values. have other 24 matrices names of them are:

the name of a1 data-00.img , name of a2 data-01.img, name of a3 data-02.img.........the name of a24 data-23.img

what want @ first value in if na,return na if there value illustration 12, search in names of other matrices (should data-12.img) , extract corresponding value , set instead of 12 value in a.finally, same values in a.

any help appreciated!

= matrix( c(2, 4, 3, 1, 5, 7), nrow=2,ncol=3, byrow = true) a1 = matrix( c(3, 6, 3, 1, 9, 7), nrow=2,ncol=3, byrow = true) a2 = matrix( c(2, 3, 3, 1, 8, 3), nrow=2,ncol=3, byrow = true) a3 = matrix( c(2, 9, 3, 1, 5, 7), nrow=2,ncol=3, byrow = true) ...... a24 = matrix( c(2,9, 3, 1, 7, 7), nrow=2,ncol=3, byrow = true)

above tried give reproducible example.

question not clear, think need:

#dummy info = matrix( c(2, 4, na, 1, 5, 7), nrow=2,ncol=3, byrow = true) a1 = matrix( c(1:6), nrow=2,ncol=3, byrow = true) a2 = matrix( c(7:12), nrow=2,ncol=3, byrow = true) a3 = matrix( c(13:18), nrow=2,ncol=3, byrow = true) a4 = matrix( c(19:24), nrow=2,ncol=3, byrow = true) a5 = matrix( c(25:30), nrow=2,ncol=3, byrow = true) a6 = matrix( c(31:36), nrow=2,ncol=3, byrow = true) a7 = matrix( c(37:42), nrow=2,ncol=3, byrow = true) #result matrix(sapply(seq_along(a), function(i){ if(is.na(a[i])) na else get(paste0("a",a[i]))[i] }), nrow=2) # [,1] [,2] [,3] # [1,] 7 20 na # [2,] 4 29 42

r matrix

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -