R function inv