I have been converting an R script into python script and I stumbled upon this strange way of calling lapply() function in R. It's a github project (SnoLyze) that I am converting into python.
lapply(conjunctionAttributeSet, "[", , "sctid")
Let's suppose the first argument is a list with values, named conjunctionAttributeSet. What about these others? Shouldn't this function take two arguments, X and FUN? This code is working fine too! How? What am I missing?
The function being applied is [
, with extra blank argument ,
and an extra argument "sctid"
. This is saying "extract the "sctid" column from each element of conjunctionAttributeSet
.
The code results = lapply(conjunctionAttributeSet, "[", , "sctid")
is equivalent to
results = list()
for(i in seq_along(conjunctionAttributeSet)) {
results[[i]] = conjunctionAttributeSet[[i]][, "sctid"]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.