File: subassign-methods.Rd

package info (click to toggle)
rmatrix 1.7-4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,096 kB
  • sloc: ansic: 97,203; makefile: 280; sh: 165
file content (136 lines) | stat: -rw-r--r-- 5,802 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
\name{subassign-methods}
\title{Methods for "[<-" - Assigning to Subsets for 'Matrix'}
%
\docType{methods}
\keyword{array}
\keyword{methods}
%
\alias{[<-}
\alias{[<--methods}
\alias{subassign-methods}
%
\alias{[<-,CsparseMatrix,Matrix,missing,replValue-method}
\alias{[<-,CsparseMatrix,index,index,replValue-method}
\alias{[<-,CsparseMatrix,index,index,sparseVector-method}
\alias{[<-,CsparseMatrix,index,missing,replValue-method}
\alias{[<-,CsparseMatrix,index,missing,sparseVector-method}
\alias{[<-,CsparseMatrix,matrix,missing,replValue-method}
\alias{[<-,CsparseMatrix,missing,index,replValue-method}
\alias{[<-,CsparseMatrix,missing,index,sparseVector-method}
\alias{[<-,Matrix,ANY,ANY,ANY-method}
\alias{[<-,Matrix,ANY,ANY,Matrix-method}
\alias{[<-,Matrix,ANY,ANY,matrix-method}
\alias{[<-,Matrix,ANY,missing,Matrix-method}
\alias{[<-,Matrix,ANY,missing,matrix-method}
\alias{[<-,Matrix,ldenseMatrix,missing,replValue-method}
\alias{[<-,Matrix,lsparseMatrix,missing,replValue-method}
\alias{[<-,Matrix,matrix,missing,replValue-method}
\alias{[<-,Matrix,missing,ANY,Matrix-method}
\alias{[<-,Matrix,missing,ANY,matrix-method}
\alias{[<-,Matrix,ndenseMatrix,missing,replValue-method}
\alias{[<-,Matrix,nsparseMatrix,missing,replValue-method}
\alias{[<-,RsparseMatrix,index,index,replValue-method}
\alias{[<-,RsparseMatrix,index,index,sparseVector-method}
\alias{[<-,RsparseMatrix,index,missing,replValue-method}
\alias{[<-,RsparseMatrix,index,missing,sparseVector-method}
\alias{[<-,RsparseMatrix,matrix,missing,replValue-method}
\alias{[<-,RsparseMatrix,missing,index,replValue-method}
\alias{[<-,RsparseMatrix,missing,index,sparseVector-method}
\alias{[<-,TsparseMatrix,Matrix,missing,replValue-method}
\alias{[<-,TsparseMatrix,index,index,replValue-method}
\alias{[<-,TsparseMatrix,index,index,sparseVector-method}
\alias{[<-,TsparseMatrix,index,missing,replValue-method}
\alias{[<-,TsparseMatrix,index,missing,sparseVector-method}
\alias{[<-,TsparseMatrix,matrix,missing,replValue-method}
\alias{[<-,TsparseMatrix,missing,index,replValue-method}
\alias{[<-,TsparseMatrix,missing,index,sparseVector-method}
\alias{[<-,denseMatrix,index,index,replValue-method}
\alias{[<-,denseMatrix,index,missing,replValue-method}
\alias{[<-,denseMatrix,matrix,missing,replValue-method}
\alias{[<-,denseMatrix,missing,index,replValue-method}
\alias{[<-,denseMatrix,missing,missing,ANY-method}
\alias{[<-,diagonalMatrix,index,index,replValue-method}
\alias{[<-,diagonalMatrix,index,index,sparseMatrix-method}
\alias{[<-,diagonalMatrix,index,index,sparseVector-method}
\alias{[<-,diagonalMatrix,index,missing,replValue-method}
\alias{[<-,diagonalMatrix,index,missing,sparseMatrix-method}
\alias{[<-,diagonalMatrix,index,missing,sparseVector-method}
\alias{[<-,diagonalMatrix,matrix,missing,replValue-method}
\alias{[<-,diagonalMatrix,missing,index,replValue-method}
\alias{[<-,diagonalMatrix,missing,index,sparseMatrix-method}
\alias{[<-,diagonalMatrix,missing,index,sparseVector-method}
\alias{[<-,diagonalMatrix,missing,missing,ANY-method}
\alias{[<-,indMatrix,index,index,ANY-method}
\alias{[<-,indMatrix,index,missing,ANY-method}
\alias{[<-,indMatrix,missing,index,ANY-method}
\alias{[<-,indMatrix,missing,missing,ANY-method}
\alias{[<-,sparseMatrix,ANY,ANY,sparseMatrix-method}
\alias{[<-,sparseMatrix,ANY,missing,sparseMatrix-method}
\alias{[<-,sparseMatrix,missing,ANY,sparseMatrix-method}
\alias{[<-,sparseMatrix,missing,missing,ANY-method}
\alias{[<-,sparseVector,index,missing,ANY-method}
\alias{[<-,sparseVector,sparseVector,missing,ANY-method}
%
\description{
  Methods for \code{"[<-"}, i.e., extraction or subsetting mostly of
  matrices, in package \pkg{Matrix}.

  \bold{Note}: Contrary to standard \code{\link{matrix}} assignment in
  base \R, in \code{x[..] <- val} it is typically an \bold{error} (see
  \code{\link{stop}}) when the \link{type} or \code{\link{class}} of
  \code{val} would require the class of \code{x} to be changed, e.g.,
  when \code{x} is logical, say \code{"lsparseMatrix"}, and \code{val}
  is numeric.
  In other cases, e.g., when \code{x} is a \code{"nsparseMatrix"} and
  \code{val} is not \code{TRUE} or \code{FALSE}, a warning is signalled,
  and \code{val} is \dQuote{interpreted} as \code{\link{logical}}, and
  (logical) \code{\link{NA}} is interpreted as \code{TRUE}.
}
\section{Methods}{
  There are \emph{many many} more than these:
  \describe{
    \item{x = "Matrix", i = "missing", j = "missing", value= "ANY"}{
      is currently a simple fallback method implementation which ensures
      \dQuote{readable} error messages.}
    \item{x = "Matrix", i = "ANY", j = "ANY", value= "ANY"}{ currently
      gives an error }

    \item{x = "denseMatrix", i = "index", j = "missing", value= "numeric"}{ ... }
    \item{x = "denseMatrix", i = "index", j = "index", value= "numeric"}{ ... }
    \item{x = "denseMatrix", i = "missing", j = "index", value= "numeric"}{ ... }
  }
}
\seealso{
  %% ./Xtrct-methods.Rd:
  \code{\link{[-methods}} for subsetting \code{"Matrix"} objects; the
  \code{\linkS4class{index}} class;
  \code{\link{Extract}} about the standard subset assignment (and extraction).
}
\examples{
\dontshow{ % for R_DEFAULT_PACKAGES=NULL
library(stats, pos = "package:base", verbose = FALSE)
}
%% Note that ./Xtrct-methods.Rd has the indexing ones
set.seed(101)
(a <- m <- Matrix(round(rnorm(7*4),2), nrow = 7))

a[] <- 2.2 # <<- replaces **every** entry
a
## as do these:
a[,] <- 3 ; a[TRUE,] <- 4

m[2, 3]  <- 3.14 # simple number
m[3, 3:4]<- 3:4  # simple numeric of length 2

## sub matrix assignment:
m[-(4:7), 3:4] <- cbind(1,2:4) #-> upper right corner of 'm'
m[3:5, 2:3] <- 0
m[6:7, 1:2] <- Diagonal(2)
m

## rows or columns only:
m[1,] <- 10
m[,2] <- 1:7
m[-(1:6), ] <- 3:0 # not the first 6 rows, i.e. only the 7th
as(m, "sparseMatrix")
}