How do I use arguments of a function when using sapply?

前端 未结 2 1091
滥情空心
滥情空心 2021-01-22 09:49

I have a dataset which I created by column binding using the cbindX function from the gdata package. This function allows me to bind columns with diffe

相关标签:
2条回答
  • 2021-01-22 10:06

    Try this.

    sapply(allcolscomb,sd, na.rm = TRUE)
    

    in the apply family functions the syntax is (data, fun, ...). The three dots are "ellipsis", they are there to host the arguments of the function passed to the apply's function.

    0 讨论(0)
  • 2021-01-22 10:25

    You should read ?sapply manual. Below example of sapply with some extra arguments:

    sapply(allcolscomb, sd, na.rm=TRUE)
    sapply(allcolscomb, function(x) sd(x, na.rm=TRUE))
    
    0 讨论(0)
提交回复
热议问题