define a variable of type list of different lengths
1
0
Entering edit mode
7.8 years ago
zzzahiri • 0

hi How can define a variable of type list of different lengths? and how can define n different xS in the for loop? for example

xS in for loop

library(seqinr)
x1=read.fasta("dbppt.fasta", seqtype="AA")
library(protr)
x2=getSequence(x1)
s=matrix(data = NA, nrow = 31012, ncol = 1, byrow = FALSE,dimnames = NULL)
for(n in 1:31012) {
  s[n]= c2s(x2[[n]])

}
for(n in 1:31012){
  xS=protseg(s[n] , aa="S", k=7)
}
R sequence • 976 views
ADD COMMENT
0
Entering edit mode

Simple. Don't use a for loop.

... blah blah blah
n_to_protseg <- function(n, X = x2){
  protseg(  c2s(X[[n]]), aa = 'S', k = 7 )}

xS <- lapply(1:31012, n_to_protseg)
ADD REPLY
0
Entering edit mode
7.8 years ago
zzzahiri • 0
library(seqinr)
x1=read.fasta("dbppt.fasta", seqtype="AA")
library(protr)
x2=getSequence(x1)
s=matrix(data = NA, nrow = 31012, ncol = 1, byrow = FALSE,dimnames = NULL)
for(n in 1:31012) {
  s[n]= c2s(x2[[n]])

}

xS=list()

for(n in 1:31012){
  xS[[n]]=protseg(s[n] , aa="S", k=7)
}
ADD COMMENT

Login before adding your answer.

Traffic: 3252 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6