How to successively combine years and months using purrr

21 görüntüleme
İlk okunmamış mesaja atla

BHM

okunmadı,
27 Nis 2017 10:57:2627.04.2017
alıcı manipulatr
Hi, 

-----------------------------------
PROBLEM STATEMENT
-----------------------------------
I want to generate URLS for each month for each year as follows:

[...]
[...]

-----------------------------------
CODE
-----------------------------------
Here is my attempt:

tail.f.name = ".csv.zip"
v.i = str_pad(1:12,2,pad="0") 

map_chr(2015:2017, ~sprintf(head.f.name,.)) %>%
  map2_chr(v.i,~str_replace(.,"[:upper:]$") )


-----------------------------------
ERROR 
-----------------------------------
But I get an error:
Error: `.x` (3) and `.y` (12) are different lengths


Should not the smaller vector be recycled in this case.




Br / 

Ista Zahn

okunmadı,
27 Nis 2017 11:40:0427.04.2017
alıcı BHM, manipulatr
On Thu, Apr 27, 2017 at 10:57 AM, BHM <ulh...@gmail.com> wrote:
> Hi,
>
> -----------------------------------
> PROBLEM STATEMENT
> -----------------------------------
> I want to generate URLS for each month for each year as follows:
>
> [...]
> https://s3.amazonaws.com/data/201611.csv.zip
> https://s3.amazonaws.com/data/201612.csv.zip
> https://s3.amazonaws.com/data/201701.csv.zip
> https://s3.amazonaws.com/data/201702.csv.zip
> [...]
>
> -----------------------------------
> CODE
> -----------------------------------
> Here is my attempt:
>
> head.f.name = "https://s3.amazonaws.com/data/%sA"
> tail.f.name = ".csv.zip"
> v.i = str_pad(1:12,2,pad="0")
>
> map_chr(2015:2017, ~sprintf(head.f.name,.)) %>%
> map2_chr(v.i,~str_replace(.,"[:upper:]$") )
>

That seems more complicated than it needs to be. How about

> years <- 2015L:2017L
> months <- str_pad(1:12,2,pad="0")
> str_c("https://s3.amazonaws.com/data/", years, rep(months, length(years)), ".csv.zip")


?

>
> -----------------------------------
> ERROR
> -----------------------------------
> But I get an error:
> Error: `.x` (3) and `.y` (12) are different lengths
>
>
> Should not the smaller vector be recycled in this case.

No, see ?map2

Best,
Ista
>
>
>
>
> Br /
>
> --
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to manipulatr+...@googlegroups.com.
> To post to this group, send email to manip...@googlegroups.com.
> Visit this group at https://groups.google.com/group/manipulatr.
> For more options, visit https://groups.google.com/d/optout.

Burhan ul haq

okunmadı,
27 Nis 2017 12:22:2027.04.2017
alıcı Ista Zahn, manipulatr
1. Thanks for the suggestion - It works :) 


2. For map2 - you are right, it says:

.x, .y
Vectors of the same length. A vector of length 1 will be recycled.




Br / 

Tümünü yanıtla
Yazarı yanıtla
Yönlendir
0 yeni ileti