0

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?

Muhammad Yasir
  • 198
  • 1
  • 10

1 Answers1

3

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"]
}

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294