我正在写一个函数向R中的客户端发送电子邮件。我正在使用mailR包来这样做,但我的服务提供者只允许我发送每小时发送100封电子邮件。我想要做的是,如果假设我的电子邮件列表中包含270个电子邮件地址,我想将其分发到chunk1=100 , chunk2 = 100 & chunk3 = 70
然后,它应该发送电子邮件到第一个块,然后等待一个小时,然后块chunk2等等。 这是我的功能模样。如何将数据帧拆分为特定行数的if循环中的R
email <- function(dataframe,city,date){
dataframe$registrant_email <- tolower(dataframe$registrant_email)
dataframe_city <- dataframe[dataframe$registrant_city == city & dataframe$create_date == date, ]
# Removing NA's and blank email ids
dataframe_city <- dataframe_city[!(is.na(dataframe_city$registrant_email)|dataframe_city$registrant_email==""), ]
# Removing duplicate email ids
dataframe_city <-dataframe_city[!duplicated(dataframe_city$registrant_email),]
emails <- as.vector(dataframe_city$registrant_email)
if(length(emails) > 100){
# divide the vector into chunks of 100
} else{send_email(emails}
return(emails)
}
我需要if loop
帮助我怎么能写拆分部分插入的100块,然后调用一个函数send_email
等待了一个小时等。
要在列表中拆分向量成块,你可以使用像'X < - 1:270; chunks < - split(x,(seq_along(x)-1)%/%100)' –
使用'%/%'是美丽的,您应该将其添加为答案。 –
你能解释一下我的一行吗?输出似乎是相同的。它是否解释了一些特殊情况? – LAP