1
votes

I am facing a strange issue. Could someone help where I am going wrong. I am a noob at R. What I have known about lapply is it applies a function over a list.

Now, when I do this,

lapply(makeCacheMatrix(a),solveCache)

it gives an error

Error in x$getInverse : object of type 'closure' is not subsettable'

However when I do,

m1<-makeCacheMatrix(a)
solveCache(m1)

It gives me correct response without an error.

m1<- is indeed a list which I checked through mode(m1). So ideally lapply should work.

Could someone please help me out why lapply(makeCacheMatrix(a),solveCache) gives the error...I mean either I capture output of makeCacheMatrix(a) and pass it to lapply or I pass it directly, it should work in both the cases.

1

1 Answers

0
votes

lapply(X, FUN, ...) applies the function FUN over each element of the list X. It appears the solveCache function operates on the list as a whole, not just a single element of the list.