Running this code in R :
pr <- function(x) {
x
}
lapply(c("a" , "b") , pr)
sapply(c("a" , "b") , pr)
apply(c("a" , "b") , pr)
returns :
> pr <- function(x) {
+ x
+ }
>
> lapply(c("a" , "b") , pr)
[[1]]
[1] "a"
[[2]]
[1] "b"
>
> sapply(c("a" , "b") , pr)
a b
"a" "b"
>
> apply(c("a" , "b") , pr)
Error in match.fun(FUN) : argument "FUN" is missing, with no default
Here is my understanding of returns values of lapply
, sapply
, apply
in above context:
lapply
returns a list , is this signified by [[1]]
?
sapply
returns a vector but why are vector dimensions [1]
not returned in response?
apply
returns an error , why is this occurring?