coeffs.Rd
Extract and manipulate coefficients of ktensor and kform objects; this using the methods of the spray package.
Functions as.spray()
and nterms()
are imported from
spray.
To see the coefficients of a kform
or ktensor
object,
use coeffs()
, which returns a disord
object (this is
actually spray::coeffs()
). Replacement methods also use the
methods of the spray package. Note that disordR
discipline is enforced.
Experimental functionality for “pure” extraction and
replacement is provided, following spray version 1.0-25 or
above. Thus idiom such as a[abs(coeffs(a)) > 0.1]
or indeed
a[coeffs(a) < 1] <- 0
should work as expected.
(a <- kform_general(5,2,1:10))
#> An alternating linear map from V^2 to R with V=R^5:
#> val
#> 2 5 = 8
#> 1 5 = 7
#> 3 4 = 6
#> 2 4 = 5
#> 4 5 = 10
#> 1 4 = 4
#> 2 3 = 3
#> 1 3 = 2
#> 3 5 = 9
#> 1 2 = 1
coeffs(a) # a disord object
#> A disord object with hash 3f2a0e8670c7c27e53fa60649745f5057067487d and elements
#> [1] 8 7 6 5 10 4 3 2 9 1
#> (in some order)
coeffs(a)[coeffs(a)%%2==1] <- 100 # replace every odd coeff with 100
a
#> An alternating linear map from V^2 to R with V=R^5:
#> val
#> 1 2 = 100
#> 3 5 = 100
#> 1 3 = 2
#> 2 3 = 100
#> 1 4 = 4
#> 4 5 = 10
#> 2 4 = 100
#> 3 4 = 6
#> 1 5 = 100
#> 2 5 = 8
coeffs(a*0)
#> numeric(0)
a <- rform()
a[coeffs(a) < 5] # experimental
#> val
#> 3 4 6 = 1
#> 2 3 7 = -2
#> 1 4 6 = 3
#> 2 5 6 = -5
#> 1 3 5 = -8
#> 2 4 7 = -4
a[coeffs(a) > 3] <- 99 # experimental