File: util.Rout.save

package info (click to toggle)
r-cran-proxy 0.4-27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: ansic: 1,247; sh: 12; makefile: 5
file content (160 lines) | stat: -rwxr-xr-x 3,069 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 
> ## test C interfaces
> 
> library(proxy)

Attaching package: 'proxy'

The following objects are masked from 'package:stats':

    as.dist, dist

The following object is masked from 'package:base':

    as.matrix

> 
> set.seed(20070630)
> 
> x <- as.dist(matrix(runif(25),5,5))
> x
          1         2         3         4
2 0.8390691                              
3 0.0377036 0.3006153                    
4 0.7621676 0.9632744 0.4358104          
5 0.1211588 0.4522659 0.8005272 0.3062947
> attributes(x)
$Size
[1] 5

$call
as.dist.default(m = x)

$class
[1] "dist"

$Diag
[1] FALSE

$Upper
[1] FALSE

> 
> z <- .Call(proxy:::R_subset_dist, x, 3)
> z
dist(0)
> 
> unclass(z)
numeric(0)
attr(,"Size")
[1] 1
attr(,"call")
as.dist.default(m = x)
attr(,"Diag")
[1] FALSE
attr(,"Upper")
[1] FALSE
> 
> .Call(proxy:::R_subset_dist, x, c(1,3,5))
          1         2
2 0.0377036          
3 0.1211588 0.8005272
> 
> attr(x, "Labels") <- LETTERS[1:5]
> 
> z <- .Call(proxy:::R_subset_dist, x, c("A","C","E"))
> z
          A         C
C 0.0377036          
E 0.1211588 0.8005272
> attributes(z)
$Size
[1] 3

$call
as.dist.default(m = x)

$class
[1] "dist"

$Diag
[1] FALSE

$Upper
[1] FALSE

$Labels
[1] "A" "C" "E"

> 
> attr(x, "Labels") <- NULL
> 
> .Call(proxy:::R_rowSums_dist, x, FALSE)
[1] 1.760099 2.555225 1.574656 2.467547 1.680247
> .Call(proxy:::R_rowSums_dist, z, FALSE)
        A         C         E 
0.1588624 0.8382308 0.9216860 
> 
> .Call(proxy:::R_row_dist, x, FALSE)       # row()
 [1] 2 3 4 5 3 4 5 4 5 5
> .Call(proxy:::R_row_dist, x, TRUE)        # col()
 [1] 1 1 1 1 2 2 2 3 3 4
> 
> ## test R interfaces
> 
> dim(x)
[1] 5 5
> dimnames(x) <- letters[1:5]
> dimnames(x)
[1] "a" "b" "c" "d" "e"
> names(x)    <- LETTERS[1:5]
> names(x)
[1] "A" "B" "C" "D" "E"
> 
> row.dist(x)
 [1] 2 3 4 5 3 4 5 4 5 5
> col.dist(x)
 [1] 1 1 1 1 2 2 2 3 3 4
> 
> subset(x, c(1,3,5))
          A         C
C 0.0377036          
E 0.1211588 0.8005272
> x[[c(1,3,5)]]
          A         C
C 0.0377036          
E 0.1211588 0.8005272
> x[c(1,3,5)]                         # as usual
[1] 0.8390691 0.7621676 0.3006153
> 
> x[[-1]]                             # drop subscripts
          B         C         D
C 0.3006153                    
D 0.9632744 0.4358104          
E 0.4522659 0.8005272 0.3062947
> 
> x[[1]]                              # empty
dist(0)
> 
> ###
> 
> proc.time()
   user  system elapsed 
  0.193   0.030   0.216