[R] Converting "day of year" to "year", "month" and "day"
Jibrin Alhassan
j|br|n@@|h@@@@n @end|ng |rom unn@edu@ng
Wed Jan 20 13:48:58 CET 2021
Hello Peter,
Thanks for your input. What I need runs like this.
df1 <- read.table("SWSdata_1998_2002", header = TRUE)
> df1$date <- as.Date(paste(df1$year, df1$day),
+ Error: unexpected end of input
> df1$date <- as.Date(paste(df1$year, df1$day),format = "%Y %j",origin =
"1998-01-01")
> df2 <- df1[c("date", "SWS")]
> head(df2)
date SWS
1 1998-01-01 344
2 1998-01-02 346
3 1998-01-03 356
4 1998-01-04 332
5 1998-01-05 302
6 1998-01-06 329
I need to display 1,826 rows and not 6 rows. Copied below is a section of
my data for your kind help.
year day Hr SWS
1998 1 0 344.
1998 2 0 346.
1998 3 0 356.
1998 4 0 332.
1998 5 0 302.
1998 6 0 329.
1998 7 0 395.
1998 8 0 359.
1998 9 0 471.
1998 10 0 392.
1998 11 0 346.
1998 12 0 387.
1998 13 0 393.
1998 14 0 367.
1998 15 0 320.
1998 16 0 309.
1998 17 0 341.
1998 18 0 329.
1998 19 0 322.
1998 20 0 429.
1998 21 0 433.
1998 22 0 398.
1998 23 0 393.
1998 24 0 393.
1998 25 0 423.
1998 26 0 426.
1998 27 0 429.
1998 28 0 386.
1998 29 0 381.
1998 30 0 375.
1998 31 0 365.
1998 32 0 450.
1998 33 0 381.
1998 34 0 316.
1998 35 0 351.
1998 36 0 306.
1998 37 0 312.
1998 38 0 320.
1998 39 0 339.
1998 40 0 395.
1998 41 0 429.
1998 42 0 479.
1998 43 0 495.
1998 44 0 407.
1998 45 0 358.
1998 46 0 360.
1998 47 0 382.
1998 48 0 394.
1998 49 0 393.
1998 50 0 435.
1998 51 0 408.
1998 52 0 360.
1998 53 0 372.
1998 54 0 376.
1998 55 0 379.
1998 56 0 361.
1998 57 0 333.
1998 58 0 321.
1998 59 0 344.
1998 60 0 412.
1998 61 0 428.
1998 62 0 401.
1998 63 0 369.
1998 64 0 343.
1998 65 0 330.
1998 66 0 317.
1998 67 0 296.
1998 68 0 282.
1998 69 0 404.
1998 70 0 530.
1998 71 0 525.
1998 72 0 484.
1998 73 0 430.
1998 74 0 388.
1998 75 0 347.
1998 76 0 337.
1998 77 0 342.
1998 78 0 305.
1998 79 0 329.
1998 80 0 420.
1998 81 0 564.
1998 82 0 483.
1998 83 0 385.
1998 84 0 393.
1998 85 0 437.
1998 86 0 441.
1998 87 0 434.
1998 88 0 471.
1998 89 0 429.
1998 90 0 412.
1998 91 0 370.
1998 92 0 326.
1998 93 0 357.
1998 94 0 338.
1998 95 0 380.
1998 96 0 339.
1998 97 0 312.
1998 98 0 313.
1998 99 0 327.
1998 100 0 362.
1998 101 0 358.
1998 102 0 387.
1998 103 0 397.
1998 104 0 375.
1998 105 0 350.
1998 106 0 357.
1998 107 0 472.
1998 108 0 526.
1998 109 0 396.
1998 110 0 374.
1998 111 0 376.
1998 112 0 355.
1998 113 0 343.
1998 114 0 425.
1998 115 0 426.
1998 116 0 479.
1998 117 0 469.
1998 118 0 425.
1998 119 0 344.
1998 120 0 341.
1998 121 0 426.
1998 122 0 601.
1998 123 0 476.
1998 124 0 670.
1998 125 0 585.
1998 126 0 496.
1998 127 0 479.
1998 128 0 569.
1998 129 0 531.
1998 130 0 489.
1998 131 0 484.
1998 132 0 480.
1998 133 0 393.
1998 134 0 332.
1998 135 0 327.
1998 136 0 493.
1998 137 0 493.
1998 138 0 430.
1998 139 0 396.
1998 140 0 408.
1998 141 0 416.
1998 142 0 376.
1998 143 0 375.
1998 144 0 415.
1998 145 0 407.
1998 146 0 398.
1998 147 0 352.
1998 148 0 349.
1998 149 0 517.
1998 150 0 597.
1998 151 0 480.
1998 152 0 435.
1998 153 0 408.
1998 154 0 441.
1998 155 0 397.
1998 156 0 374.
1998 157 0 413.
1998 158 0 582.
1998 159 0 513.
1998 160 0 459.
1998 161 0 466.
1998 162 0 414.
1998 163 0 354.
1998 164 0 341.
1998 165 0 343.
1998 166 0 369.
1998 167 0 411.
1998 168 0 355.
1998 169 0 333.
1998 170 0 443.
1998 171 0 426.
1998 172 0 419.
1998 173 0 404.
1998 174 0 387.
1998 175 0 460.
1998 176 0 447.
1998 177 0 469.
1998 178 0 447.
1998 179 0 389.
1998 180 0 375.
1998 181 0 354.
1998 182 0 316.
1998 183 0 369.
1998 184 0 410.
1998 185 0 406.
1998 186 0 477.
1998 187 0 583.
1998 188 0 458.
1998 189 0 386.
1998 190 0 342.
1998 191 0 333.
1998 192 0 369.
1998 193 0 406.
1998 194 0 375.
1998 195 0 332.
1998 196 0 310.
1998 197 0 528.
1998 198 0 530.
1998 199 0 387.
1998 200 0 385.
1998 201 0 349.
1998 202 0 409.
1998 203 0 399.
1998 204 0 619.
1998 205 0 658.
1998 206 0 581.
1998 207 0 445.
1998 208 0 370.
1998 209 0 326.
1998 210 0 334.
1998 211 0 384.
1998 212 0 423.
1998 213 0 412.
1998 214 0 404.
1998 215 0 370.
1998 216 0 384.
1998 217 0 383.
1998 218 0 378.
1998 219 0 461.
1998 220 0 460.
1998 221 0 400.
1998 222 0 447.
1998 223 0 373.
1998 224 0 379.
1998 225 0 374.
1998 226 0 374.
1998 227 0 391.
1998 228 0 348.
1998 229 0 303.
1998 230 0 279.
1998 231 0 312.
1998 232 0 331.
1998 233 0 298.
1998 234 0 341.
1998 235 0 493.
1998 236 0 436.
1998 237 0 400.
1998 238 0 633.
1998 239 0 630.
1998 240 0 583.
1998 241 0 547.
1998 242 0 550.
1998 243 0 499.
1998 244 0 444.
1998 245 0 427.
1998 246 0 401.
1998 247 0 382.
1998 248 0 336.
1998 249 0 344.
1998 250 0 327.
1998 251 0 334.
1998 252 0 360.
1998 253 0 361.
1998 254 0 346.
1998 255 0 422.
1998 256 0 424.
1998 257 0 380.
1998 258 0 309.
1998 259 0 291.
1998 260 0 311.
1998 261 0 392.
1998 262 0 416.
1998 263 0 371.
1998 264 0 370.
1998 265 0 397.
1998 266 0 412.
1998 267 0 471.
1998 268 0 713.
1998 269 0 586.
1998 270 0 533.
1998 271 0 499.
1998 272 0 419.
1998 273 0 437.
1998 274 0 510.
1998 275 0 608.
1998 276 0 561.
1998 277 0 451.
1998 278 0 416.
1998 279 0 363.
1998 280 0 440.
1998 281 0 521.
1998 282 0 459.
1998 283 0 431.
1998 284 0 399.
1998 285 0 348.
1998 286 0 309.
1998 287 0 304.
1998 288 0 369.
1998 289 0 395.
1998 290 0 386.
1998 291 0 348.
1998 292 0 397.
1998 293 0 439.
1998 294 0 542.
1998 295 0 617.
1998 296 0 541.
1998 297 0 479.
1998 298 0 425.
1998 299 0 404.
1998 300 0 414.
1998 301 0 519.
1998 302 0 575.
1998 303 0 509.
1998 304 0 411.
1998 305 0 387.
1998 306 0 388.
1998 307 0 403.
1998 308 0 371.
1998 309 0 388.
1998 310 0 400.
1998 311 0 467.
1998 312 0 539.
1998 313 0 455.
1998 314 0 417.
1998 315 0 351.
1998 316 0 345.
1998 317 0 385.
1998 318 0 389.
1998 319 0 443.
1998 320 0 511.
1998 321 0 441.
1998 322 0 381.
1998 323 0 375.
1998 324 0 418.
1998 325 0 417.
1998 326 0 385.
1998 327 0 386.
1998 328 0 475.
1998 329 0 459.
1998 330 0 474.
1998 331 0 424.
1998 332 0 426.
1998 333 0 414.
1998 334 0 429.
1998 335 0 465.
1998 336 0 429.
1998 337 0 448.
1998 338 0 478.
1998 339 0 473.
1998 340 0 425.
1998 341 0 414.
1998 342 0 415.
1998 343 0 412.
1998 344 0 363.
1998 345 0 364.
1998 346 0 381.
1998 347 0 385.
1998 348 0 404.
1998 349 0 372.
1998 350 0 468.
1998 351 0 365.
1998 352 0 323.
1998 353 0 343.
1998 354 0 422.
1998 355 0 351.
1998 356 0 350.
1998 357 0 343.
1998 358 0 332.
1998 359 0 422.
1998 360 0 468.
1998 361 0 380.
1998 362 0 378.
1998 363 0 405.
1998 364 0 410.
1998 365 0 389.
1999 1 0 421.
1999 2 0 397.
1999 3 0 354.
1999 4 0 341.
1999 5 0 330.
1999 6 0 378.
1999 7 0 476.
1999 8 0 453.
1999 9 0 435.
1999 10 0 406.
1999 11 0 429.
1999 12 0 373.
1999 13 0 382.
1999 14 0 461.
1999 15 0 554.
1999 16 0 498.
1999 17 0 413.
1999 18 0 355.
1999 19 0 371.
1999 20 0 375.
1999 21 0 471.
1999 22 0 514.
1999 23 0 572.
1999 24 0 517.
1999 25 0 463.
1999 26 0 388.
1999 27 0 372.
Many thanks,
Jibrin
On Sat, Jan 16, 2021 at 6:24 PM peter dalgaard <pdalgd using gmail.com> wrote:
> Something like this?
>
> > as.Date(ISOdate(1998,1,1))+(1:100)-1
> [1] "1998-01-01" "1998-01-02" "1998-01-03" "1998-01-04" "1998-01-05"
> [6] "1998-01-06" "1998-01-07" "1998-01-08" "1998-01-09" "1998-01-10"
> [11] "1998-01-11" "1998-01-12" "1998-01-13" "1998-01-14" "1998-01-15"
> [16] "1998-01-16" "1998-01-17" "1998-01-18" "1998-01-19" "1998-01-20"
> [21] "1998-01-21" "1998-01-22" "1998-01-23" "1998-01-24" "1998-01-25"
> [26] "1998-01-26" "1998-01-27" "1998-01-28" "1998-01-29" "1998-01-30"
> [31] "1998-01-31" "1998-02-01" "1998-02-02" "1998-02-03" "1998-02-04"
> [36] "1998-02-05" "1998-02-06" "1998-02-07" "1998-02-08" "1998-02-09"
> [41] "1998-02-10" "1998-02-11" "1998-02-12" "1998-02-13" "1998-02-14"
> [46] "1998-02-15" "1998-02-16" "1998-02-17" "1998-02-18" "1998-02-19"
> [51] "1998-02-20" "1998-02-21" "1998-02-22" "1998-02-23" "1998-02-24"
> [56] "1998-02-25" "1998-02-26" "1998-02-27" "1998-02-28" "1998-03-01"
> [61] "1998-03-02" "1998-03-03" "1998-03-04" "1998-03-05" "1998-03-06"
> [66] "1998-03-07" "1998-03-08" "1998-03-09" "1998-03-10" "1998-03-11"
> [71] "1998-03-12" "1998-03-13" "1998-03-14" "1998-03-15" "1998-03-16"
> [76] "1998-03-17" "1998-03-18" "1998-03-19" "1998-03-20" "1998-03-21"
> [81] "1998-03-22" "1998-03-23" "1998-03-24" "1998-03-25" "1998-03-26"
> [86] "1998-03-27" "1998-03-28" "1998-03-29" "1998-03-30" "1998-03-31"
> [91] "1998-04-01" "1998-04-02" "1998-04-03" "1998-04-04" "1998-04-05"
> [96] "1998-04-06" "1998-04-07" "1998-04-08" "1998-04-09" "1998-04-10"
>
> Or, if you want month numbers and day of month as numerics:
>
> > as.POSIXlt(as.Date(ISOdate(1998,1,1))+(1:100)-1)$mon
> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
> 1 1 1
> [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2
> 2 2 2
> [75] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3
> > as.POSIXlt(as.Date(ISOdate(1998,1,1))+(1:100)-1)$mday
> [1] 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] 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
> 18 19
> [51] 20 21 22 23 24 25 26 27 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14
> 15 16
> [76] 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7
> 8 9 10
>
> -pd
>
> > On 16 Jan 2021, at 07:48 , Jibrin Alhassan <jibrin.alhassan using unn.edu.ng>
> wrote:
> >
> > Hi Barradas
> > Sorry for the delay. Below is a section of my data. I have up to 1826
> > covering 1998 to 2002
> > year day Hr SWS
> > 1998 1 0 344.
> > 1998 2 0 346.
> > 1998 3 0 356.
> > 1998 4 0 332.
> > 1998 5 0 302.
> > 1998 6 0 329.
> > 1998 7 0 395.
> > 1998 8 0 359.
> > 1998 9 0 471.
> > 1998 10 0 392.
> > 1998 11 0 346.
> > 1998 12 0 387.
> > 1998 13 0 393.
> > 1998 14 0 367.
> > 1998 15 0 320.
> > 1998 16 0 309.
> > 1998 17 0 341.
> > 1998 18 0 329.
> > 1998 19 0 322.
> > 1998 20 0 429.
> > 1998 21 0 433.
> > 1998 22 0 398.
> > 1998 23 0 393.
> > 1998 24 0 393.
> > 1998 25 0 423.
> > 1998 26 0 426.
> > 1998 27 0 429.
> > 1998 28 0 386.
> > 1998 29 0 381.
> > 1998 30 0 375.
> > 1998 31 0 365.
> > 1998 32 0 450.
> > 1998 33 0 381.
> > 1998 34 0 316.
> > 1998 35 0 351.
> > 1998 36 0 306.
> > 1998 37 0 312.
> > 1998 38 0 320.
> > 1998 39 0 339.
> > 1998 40 0 395.
> > 1998 41 0 429.
> > 1998 42 0 479.
> > 1998 43 0 495.
> > 1998 44 0 407.
> > 1998 45 0 358.
> > 1998 46 0 360.
> > 1998 47 0 382.
> > 1998 48 0 394.
> > 1998 49 0 393.
> > 1998 50 0 435.
> > 1998 51 0 408.
> > 1998 52 0 360.
> > 1998 53 0 372.
> > 1998 54 0 376.
> > 1998 55 0 379.
> > 1998 56 0 361.
> > 1998 57 0 333.
> > 1998 58 0 321.
> > 1998 59 0 344.
> > 1998 60 0 412.
> > 1998 61 0 428.
> > 1998 62 0 401.
> > 1998 63 0 369.
> > 1998 64 0 343.
> > 1998 65 0 330.
> > 1998 66 0 317.
> > 1998 67 0 296.
> > 1998 68 0 282.
> > 1998 69 0 404.
> > 1998 70 0 530.
> > 1998 71 0 525.
> > 1998 72 0 484.
> > 1998 73 0 430.
> > 1998 74 0 388.
> > 1998 75 0 347.
> > 1998 76 0 337.
> > 1998 77 0 342.
> > 1998 78 0 305.
> > 1998 79 0 329.
> > 1998 80 0 420.
> > 1998 81 0 564.
> > 1998 82 0 483.
> > 1998 83 0 385.
> > 1998 84 0 393.
> > 1998 85 0 437.
> > 1998 86 0 441.
> > 1998 87 0 434.
> > 1998 88 0 471.
> > 1998 89 0 429.
> > 1998 90 0 412.
> > 1998 91 0 370.
> > 1998 92 0 326.
> > 1998 93 0 357.
> > 1998 94 0 338.
> > 1998 95 0 380.
> > 1998 96 0 339.
> > 1998 97 0 312.
> > 1998 98 0 313.
> > 1998 99 0 327.
> > 1998 100 0 362.
> > 1998 101 0 358.
> > 1998 102 0 387.
> > 1998 103 0 397.
> > 1998 104 0 375.
> > 1998 105 0 350.
> > 1998 106 0 357.
> > 1998 107 0 472.
> > 1998 108 0 526.
> > 1998 109 0 396.
> > 1998 110 0 374.
> > 1998 111 0 376.
> > 1998 112 0 355.
> > 1998 113 0 343.
> > 1998 114 0 425.
> > 1998 115 0 426.
> > 1998 116 0 479.
> > 1998 117 0 469.
> > 1998 118 0 425.
> > 1998 119 0 344.
> > 1998 120 0 341.
> > 1998 121 0 426.
> > 1998 122 0 601.
> > 1998 123 0 476.
> > 1998 124 0 670.
> > 1998 125 0 585.
> > 1998 126 0 496.
> > 1998 127 0 479.
> > 1998 128 0 569.
> > 1998 129 0 531.
> > 1998 130 0 489.
> > 1998 131 0 484.
> > 1998 132 0 480.
> > 1998 133 0 393.
> > 1998 134 0 332.
> > 1998 135 0 327.
> > 1998 136 0 493.
> > 1998 137 0 493.
> > 1998 138 0 430.
> > 1998 139 0 396.
> > 1998 140 0 408.
> > 1998 141 0 416.
> > 1998 142 0 376.
> > 1998 143 0 375.
> > 1998 144 0 415.
> > 1998 145 0 407.
> > 1998 146 0 398.
> > 1998 147 0 352.
> > 1998 148 0 349.
> > 1998 149 0 517.
> > 1998 150 0 597.
> > 1998 151 0 480.
> > 1998 152 0 435.
> > 1998 153 0 408.
> > 1998 154 0 441.
> > 1998 155 0 397.
> > 1998 156 0 374.
> > 1998 157 0 413.
> > 1998 158 0 582.
> > 1998 159 0 513.
> > 1998 160 0 459.
> > 1998 161 0 466.
> > 1998 162 0 414.
> > 1998 163 0 354.
> > 1998 164 0 341.
> > 1998 165 0 343.
> > 1998 166 0 369.
> > 1998 167 0 411.
> > 1998 168 0 355.
> > Thanks
> > Jibrin
> >
> > On Fri, Jan 15, 2021 at 7:15 PM Rui Barradas <ruipbarradas using sapo.pt>
> wrote:
> >
> >> Hello,
> >>
> >> No dataset was attached. Like the posting guide says,
> >>
> >> No binary attachments except for PS, PDF, and some image and archive
> >> formats (others are automatically stripped off because they can contain
> >> malicious software). Files in other formats and larger ones should
> >> rather be put on the web and have only their URLs posted. This way a
> >> reader has the option to download them or not.
> >>
> >>
> >> Can you post sample data? Please post the output of `dput(df)`. Or, if
> >> it is too big the output of `dput(head(df, 20))`. (`df` is the name of
> >> your dataset.)
> >>
> >> Hope this helps,
> >>
> >> Rui Barradas
> >>
> >> Às 11:30 de 15/01/21, Jibrin Alhassan escreveu:
> >>> Dear R users,
> >>> I am very new to R software. I have solar wind speed data needed for my
> >>> work. How do I convert day in the year to year, month, and day with R
> >>> software? I have used this code
> >>> as.Date(0, origin = "1998-01-01")
> >>> but it can only convert one day of the year at a time. Meanwhile, I
> have
> >> up
> >>> to the 1998-2002 data set. Attached is my data.
> >>> Kindly help, please.
> >>> Jibrin Alhassan
> >>> ______________________________________________
> >>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>>
> >>
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
>
>
>
>
>
>
>
>
>
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list