0
據瞭解,我們可以abc
使用隱藏屬性/類名
class(abc) <- append(class(abc), "fun")
是abc
後會給我們加個班「好玩」:
> abc <- matrix(1:4, nr=2)
> class(abc) <- append(class(abc), "fun")
> abc
[,1] [,2]
[1,] 1 3
[2,] 2 4
attr(,"class")
[1] "matrix" "fun"
有沒有辦法來追加該類「樂趣」至abc
但未顯示
attr(,"class")
[1] "matrix" "fun"
要清楚,以下是我所得到的:
> abc <- list(1:4, letters[1:3])
> abc
[[1]]
[1] 1 2 3 4
[[2]]
[1] "a" "b" "c"
> class(abc) <- append(class(abc), "fun")
> abc
[[1]]
[1] 1 2 3 4
[[2]]
[1] "a" "b" "c"
attr(,"class")
[1] "list" "fun"
> class(abc)
[1] "list" "fun"
但我想:
> abc <- list(1:4, letters[1:3])
> abc
[[1]]
[1] 1 2 3 4
[[2]]
[1] "a" "b" "c"
> class(abc) <- append(class(abc), "fun")
> abc
[[1]]
[1] 1 2 3 4
[[2]]
[1] "a" "b" "c"
> class(abc)
[1] "list" "fun"
謝謝!