Reputation: 23
I am trying this and I'm not getting the required output which should be different for different sequences.
oops <- function(x){
aacom <- Peptides::aaComp(x)
aacom
c <- data.frame(aacom)
y <- c %>% select(Number)
Tiny_Number<- y[1,]
return(Tiny_Number)
}
oops(c("GLFDIIKKIAESF","KWKLFKKIGAVLKVL")
Upvotes: 1
Views: 44
Reputation: 76402
Try with map
, since aaComp
returns a list.
library(Peptides)
library(dplyr)
library(purrr)
oops <- function(x){
aacom <- Peptides::aaComp(x)
aacom %>%
map(~as.data.frame(.)) %>%
map(~select(., Number)) %>%
map(~`[`(., 1, ))
}
oops(c("GLFDIIKKIAESF","KWKLFKKIGAVLKVL"))
#[[1]]
#[1] 3
#
#[[2]]
#[1] 2
Another version of the pipe.
oops <- function(x){
aacom <- Peptides::aaComp(x)
aacom %>%
map(~as.data.frame(.) %>% select(., Number) %>% `[`(., 1, ))
}
Here is a function with no need for pipes and 3 calls to map
. Its output is the same as above.
oops <- function(x){
y <- Peptides::aaComp(x)
lapply(y, '[', 1, 'Number')
}
Upvotes: 1