0

I am performing an analysis in R. I want to fill the first row of an matrix with the content of a table. The problem I have is that the content of the table is variable depending on the data so sometimes certain identifiers that appear in the matrix do not appear in the table.

> random.evaluate
     DNA LINE LTR/ERV1 LTR/ERVK LTR/ERVL LTR/ERVL-MaLR other SINE
[1,]  NA   NA       NA       NA       NA            NA    NA   NA

> y
  DNA          LINE      LTR/ERVK      LTR/ERVL LTR/ERVL-MaLR     SINE 
    1             1             1             1             1       4

Due to this, when I try to join the data of the matrix with the data of the table, I get the following error

random.evaluate[1,] <- y
Error in random.evaluate[1, ] <- y : 
  number of items to replace is not a multiple of replacement length

Could someone help me fix this bug? I have found solutions to this error but in my case they do not work for me.

  • Hello @Fernandogs97. Welcome on SO! Please provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that other SO users can help you the best way. – lovalery Nov 02 '21 at 20:25

1 Answers1

1

First check if the column names of the table exist in the matrix

Check this link

If it exists, just set the value as usual.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Francisco Ghelfi
  • 872
  • 1
  • 11
  • 34