Extract text from a file in R

1

I have a .txt file with a fixed-length DNA string and I want you to return an array of text with different fragments.

I read the file with the following code:

dades<- read.table("DnaSeq.txt")

Example:

I have the string:

tgcaggctttgcacatgtgac

and I want you to return me:

posicion valor
  1      tgc
  2      agg
  3      ctt
  4      tgc
  5      aca
  6      tgt
  7      gac

Solution:

dades<- read.table("DnaSeq.txt")
dades<-dades$V1
DNA <- substr(dades,0,3)
    
asked by francesc 09.03.2017 в 10:27
source

1 answer

1

This function seems to work fine:

aaa <- strsplit("la cadena que tienes", "(?<=.{3})", perl = TRUE)[[1]]

Then you create a data.frame and that's it.

DNA <- data.frame("posicion" = seq(1,length(aaa)),
                  "valor" = aaa[1:length(aaa)])
    
answered by 10.03.2017 в 13:43