diag.spam(2, 4) # 2*I4
smat <- diag.spam(1:5)
diag( smat)
diag( smat) <- 5:1
# The last line is equivalent to
diag.spam( smat) <- 5:1
# Note that diag.spam( 1:5) <- 5:1 not work of course.
Run the code above in your browser using DataLab