I have variable lr_temp and it is RAW(8) type. Making on it RawToHex(lr_temp) I receive string: BDAB59967DF11ECC (8 bytes presented in hex). My problem is to receive integer value for each byte:
dbms_output.put_line(RawToHex(lr_temp));
FOR i IN 1 .. 8
LOOP
dbms_output.put_line(ascii(utl_raw.substr(lr_temp, i, 1)));
END LOOP;
I receive:
BDAB59967DF11ECC
66
65
53
57
55
70
49
67
But BD is 189 not 66, AB is 171 not 65 and so on..
dbms_output.put_line(RawToHex(lr_temp));
FOR i IN 1 .. lcn_data_length
LOOP
dbms_output.put_line(utl_raw.cast_to_binary_integer(utl_raw.substr(lr_temp, i, 1)));
END LOOP;
and the output:
BDAB59967DF11ECC
189
171
89
150
125
241
30
204
Related
I have to rename several tens of thousands of audio files of 5 seconds each, each of them coming from a file of 5 minutes (5minutes/5secondes = 60 files). To do this I need to define the time (hour, minute and second) of the beginning of the 5 minutes recording and I tried to make a clock that advances from 5 seconds to 5 seconds and that keep the values of seconds, minutes and hours in vectors to rename the files using these vectors like this:
stwd("")
name = "Car041512-2021-Pass1-Z2_20210914_211000_" #file name prefix
hours = 21
minutes = 19
seconde = 9
for (i in 0:59) {
seconde[i+1] = secondes + i*5
if(seconde[i+1] >= 60)
seconde[i+1] = seconde[i+1] - 60
minute[i+1]= minutes+1
if (minute >= 60)
minutes = 0
hour[i+1] = hours + 1
}
time = as.character(paste0(hour,minute,seconde))
list =list.files(all.files=F)
rename = paste0(name,time,".wav")
file.rename(list, rename)
I have a problem at the beginning of the loop. The seconds vector does not exceed 60 seconds but only during 2 cycles and I do not see why. This is the first time I've done loops with R and I must have made a lot of mistakes.
seconde
[1] 9 14 19 24 29 34 39 44 49 54 59 4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94 99 104 109 114 119 124 129 134 139 144 149 154 159 164 169 174 179 184 189 194 199 204 209 214 219 224 229 234 239 244
The renaming of the files works correctly, it's just the loop that doesn't work correctly. Can you help me?
Thanks in advance.
The contingency table of my data shows that there is one element with 21974 value. However, a which function cannot locate where it is. I am wondering if my code has an error or not.
I have the following code:
table(as.numeric(dat[1,2:ncol(dat)]))
# And the result is:
#(Upper: Groups / Bottom: Frequency for each group)
53 58 59 60 65 67 71 72 74 75 78 79 80 81 82 84 88 89 94 21974
143 142 70 226 63 95 89 181 147 344 131 896 480 205 84 159 351 475 364 1
There is one element in a group "21974".
However if I use a which function to figure out where it is, my code cannot locate it:
which(dat[1,] == "21974", arr.ind=T)
Its result is:
row col
I am not sure how this happens and would like to know if I misused the which function.
I think you can use match: match(21974, df) to give you a position in a vector such as df$colname. I think (I've not used it), this would work to find the position in the row as well:
df[match(21974,df$colname),]
i need to distribute some days along the year.
I have 213 activities and 247 days.. i need to plan this activities, but i need to cover the maximum time what can be possible.
I am substracting the total days - activities, in this case 34, i divide the total days with the previous result: 247/34= 7,26...
With this number i know what every seven days y have one without activity.
To code this part i doing this:
where day is a "for" variable what its looping a dataframe with dates and integer its the integer part of 7,26, in this case 7
if(day%%integer==0) {
aditional <- 0
} else {
aditional <- 1
}
#
if(day%%7==0) {
aditional <- 0
} else {
aditional <- 1
}
The result will be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
In bold font the day without activity
This way its cool, but its not so precise how i want.
I know i need to use the decimal part of the result of 7,26... 26, but i dont know how do it.
Can you help me please?
Thanks and sorry for my english
Make these 34 days the non-activity days:
round((247/34) * seq(34))
giving:
[1] 7 15 22 29 36 44 51 58 65 73 80 87 94 102 109 116 124 131 138
[20] 145 153 160 167 174 182 189 196 203 211 218 225 232 240 247
> my_query <- paste("select * from", query_table, "where Arrived_Date_Time >=", arrived_earliest_date, "and Arrived_Date_Time < ", arrived_latest_date)
> dfDataIn <- sqlQuery(NSSP, my_query, stringsAsFactors=FALSE)
> odbcCloseAll()
> table(dfDataIn$Discharge_Disposition)
1 2 3 4 5 6 7 8 9 20 21
64059 336 1522 32 306 1166 2343 1 35423 312 36
30 41 43 50 51 61 62 63 64 65 66
26 18 295 133 200 5 270 76 3 1121 811
70 100
249 24
Actually dfDataIn$Discharge_Disposition is a character variable, and most importantly, most 1 here are supposed to be "01" in the database, whereas only minority are truly "1" in the database. (similarly for 2-9)
Is there any way to read the data in the right format?
You could try as.is = TRUE.
dfDataIn <- sqlQuery(NSSP, my_query, as.is = TRUE)
This will bring the data as is from the data source.
My objective is to list the drift coefficient from a random walk with drift forecast function, applied to a set of historical data (below). Specifically I am trying to gather the drift coefficient starting from the random walk with drift model of the first year, then cumulatively to the last, recording the coefficient each time, meaning iteratively or each additional year (recording this into a list? if that is appropriate). To be clear each new random walk forecast is including all the previous years.
The data is a list of 241 consumption levels, and I am attempting to discern how the drift coefficent would change over the course of iteratively progressing from n=1 to n=241
Where for example the random walk with drift model is Y[t] = c + Y[t-1] + Z[t] where Z[t] is a normal error and c is the coefficient i am looking for. My current attempts at this involve a for loop function and extracting the c coefficient from the rwf() function from the "Forecast" package in R.
To extract this, I am doing as such
rwf(x, h = 1, drift = TRUE)$model[[1]]
which extracts the drift coefficient.
The problem is, my attempts at subsetting the data within the rwf call have failed, and I also don't believe, through trial and error and research, that rwf() supports the subset argument, as an lm model does for example. In this sense my attempts at looping the function have also failed.
An example of such code is
for (i in 1:5){print((rwf(x[1:i], h = 1, drift = TRUE))$model[[1]])}
which gives me the following error
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
0 (non-NA) cases
In addition: Warning message:
In is.na(rows) : is.na() applied to non-(list or vector) of type 'NULL'
Any help would be much appreciated.
I read SO a lot for help but this is my first time asking a question.
The data is as follows
PCE
1 1306.7
2 1309.6
3 1335.3
4 1341.8
5 1389.2
6 1405.7
7 1414.2
8 1411.0
9 1401.6
10 1406.7
11 1425.0
12 1444.4
13 1474.7
14 1507.8
15 1536.6
16 1555.6
17 1575.2
18 1577.8
19 1583.0
20 1586.6
21 1608.4
22 1619.5
23 1622.4
24 1635.3
25 1636.1
26 1613.9
27 1627.1
28 1653.8
29 1675.6
30 1706.7
31 1732.9
32 1751.0
33 1752.9
34 1769.7
35 1792.1
36 1785.0
37 1787.4
38 1786.9
39 1813.4
40 1822.2
41 1858.7
42 1878.5
43 1901.6
44 1917.0
45 1944.2
46 1957.3
47 1976.0
48 2002.9
49 2019.6
50 2059.5
51 2095.8
52 2134.3
53 2140.2
54 2187.8
55 2212.0
56 2250.0
57 2313.2
58 2347.4
59 2353.5
60 2380.4
61 2390.3
62 2404.2
63 2437.0
64 2449.5
65 2464.6
66 2523.4
67 2562.1
68 2610.3
69 2622.3
70 2651.7
71 2668.6
72 2681.5
73 2702.9
74 2719.5
75 2731.9
76 2755.9
77 2748.4
78 2800.9
79 2826.6
80 2849.1
81 2896.5
82 2935.2
83 2991.2
84 3037.4
85 3108.6
86 3165.5
87 3163.9
88 3175.3
89 3166.0
90 3138.3
91 3149.2
92 3162.2
93 3115.8
94 3142.0
95 3194.4
96 3239.9
97 3274.2
98 3339.6
99 3370.3
100 3405.9
101 3450.3
102 3489.7
103 3509.0
104 3542.5
105 3595.9
106 3616.9
107 3694.2
108 3709.7
109 3739.6
110 3758.5
111 3756.3
112 3793.2
113 3803.3
114 3796.7
115 3710.5
116 3750.3
117 3800.3
118 3821.1
119 3821.1
120 3836.6
121 3807.6
122 3832.2
123 3845.9
124 3875.4
125 3946.1
126 3984.8
127 4063.9
128 4135.7
129 4201.3
130 4237.3
131 4297.9
132 4331.1
133 4388.1
134 4462.5
135 4503.2
136 4588.7
137 4598.8
138 4637.2
139 4686.6
140 4768.5
141 4797.2
142 4789.9
143 4854.0
144 4908.2
145 4920.0
146 5002.2
147 5038.5
148 5078.3
149 5138.1
150 5156.9
151 5180.0
152 5233.7
153 5259.3
154 5300.9
155 5318.4
156 5338.6
157 5297.0
158 5282.0
159 5322.2
160 5342.6
161 5340.2
162 5432.0
163 5464.2
164 5524.6
165 5592.0
166 5614.7
167 5668.6
168 5730.1
169 5781.1
170 5845.5
171 5888.8
172 5936.0
173 5994.6
174 6001.6
175 6050.8
176 6104.9
177 6147.8
178 6204.0
179 6274.2
180 6311.8
181 6363.2
182 6427.3
183 6453.3
184 6563.0
185 6638.1
186 6704.1
187 6819.5
188 6909.9
189 7015.9
190 7085.1
191 7196.6
192 7283.1
193 7385.8
194 7497.8
195 7568.3
196 7642.4
197 7710.0
198 7740.8
199 7770.0
200 7804.2
201 7926.4
202 7953.7
203 7994.1
204 8048.3
205 8076.9
206 8117.7
207 8198.1
208 8308.5
209 8353.7
210 8427.6
211 8465.1
212 8539.1
213 8631.3
214 8700.1
215 8786.2
216 8852.9
217 8874.9
218 8965.8
219 9019.8
220 9073.9
221 9158.3
222 9209.2
223 9244.5
224 9285.2
225 9312.6
226 9289.1
227 9285.8
228 9196.0
229 9076.0
230 9040.9
231 8998.5
232 9050.3
233 9060.2
234 9121.2
235 9186.9
236 9247.1
237 9328.4
238 9376.7
239 9392.7
240 9433.5
241 9482.1
You need at least two points to fit your model. Here's how I'd approach the problem after reading your data into a data.frame named x:
library(forecast)
drifts <- sapply(2:nrow(x), function(zz) rwf(x[1:zz,], drift = TRUE)$model$drift)
I'm not sure if this is what you were expecting or not, but here's a plot of your drift values: