I am trying to build a data frame named 'df' that registers the time stamp when each row was entered. 'df' should have a unique column:
The data I want to input in 'df' is from data frame 'a', column 'textid':
str(a$textid)
chr [1:262] "xxxxx yyy" ...
'a' is composed as:
str(a)
'data.frame': 262 obs. of 3 variables: $ V1 : chr "Refierenos alguien que compre o arriende, si concreta obtén un ingreso extra \n\ngoo.gl/OlPYuZ" "Menciona a un amigo que quiera comprar una propiedad, si concreta, consigue dinero plus\n\ngoo.gl/OlPYuZ" "Refierenos alguien que compre o arriende, si concreta obtén un ingreso extra \n\ngoo.gl/OlPYuZ" "Menciona a un amigo que quiera comprar una propiedad, si concreta, consigue dinero plus\n\ngoo.gl/OlPYuZ" ... $ textid: chr "xxxxx yyyy" ... $ limit : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
dput(droplevels(head(a)))
structure(list(V1 = c("Refierenos alguien que compre o arriende, si concreta obtén un ingreso extra \n\ngoo.gl/OlPYuZ", "Menciona a un amigo que quiera comprar una propiedad, si concreta, consigue dinero plus\n\ngoo.gl/OlPYuZ", "Refierenos alguien que compre o arriende, si concreta obtén un ingreso extra \n\ngoo.gl/OlPYuZ", "Menciona a un amigo que quiera comprar una propiedad, si concreta, consigue dinero plus\n\ngoo.gl/OlPYuZ", "Refierenos alguien que compre o arriende, si concreta obtén un ingreso extra \n\ngoo.gl/OlPYuZ", "Menciona a un amigo que quiera comprar una propiedad, si concreta, consigue dinero plus\n\ngoo.gl/OlPYuZ" ), textid = c("xxxxx yyy", "xxxxx yyy", "xxxxx yyy", "xxxxx yyy", "xxxxx yyy", "xxxxx yyy" ), limit = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)), .Names = c("V1", "textid", "limit"), row.names = c(NA, 6L), class = "data.frame")
I need a condition for time. Every row has to be input if:
if(as.integer(Sys.time()) %% 11 & as.integer(Sys.time()) %% 17 != 0)
After the row is entered there should be a loop that should wait for the next time that Sys.Time() (coerced as an integer value) matches that condition.
For that I have built this code:
df <- c(NA)
df <- as.data.frame(matrix(c(a), nrow = nrow(a)))
i=1
while(i <= nrow(a)) {
repeat {
if (as.integer(Sys.time()) %% 11 & as.integer(Sys.time()) %% 17 != 0) {
break
} else {
df[i,]<- paste(Sys.time(),a$textid[i])
i=i+1
}
}
}
Unsuccesfully I am obtaining al df's rows at the same time with the same time stamp.
str(df)
'data.frame': 2982 obs. of 1 variable: $ c(NA): chr "2017-07-10 13:14:58 xxxxx yyy" ...
Then I have tried
i=1
while(i<=nrow(ids) & as.integer(Sys.time()) %% 11 == 0 & as.integer(Sys.time()) %% 17 == 0) {
df[i,]<-paste(Sys.time(),a$textid[i])
i=1+i
}
but I get an empty 'df'.
Finnally I am trying:
i=1
df<-as.data.frame(c(NA))
repeat{
if(as.integer(Sys.time()) %% 11 & as.integer(Sys.time()) %% 17 == 0{
df[i,]<-paste(Sys.time(),a$textid[i])
i=1+i
}
if(i>nrow(ids)){
break
}
}
But 'a's´ rows keep entering at the same time to 'df' and do not loop looking for the next condition in time that matches before entering each row.
dput(droplevels(head(df)))
structure(list(
c(NA)
= c("2017-07-11 16:30:46 xxxx yyyy", "2017-07-11 16:30:46 xxxxx yyy", "2017-07-11 16:30:46 xxxxx yyy", "2017-07-11 16:30:46 xxxxx yyy", "2017-07-11 16:30:46 xxxxx yyy", "2017-07-11 16:30:46 xxxxx yyy" )), .Names = "c(NA)", row.names = c(NA, 6L), class = "data.frame")
As you can see the time is the same for every row. What I am trying to get is something like:
structure(list(
c(NA)
= c("2017-07-11 16:30:46 xxxx yyyy", "2017-07-11 16:31:12 xxxxx yyy", "2017-07-11 16:31:51 xxxxx yyy", "2017-07-11 16:33:33 xxxxx yyy", "2017-07-11 16:33:35 xxxxx yyy", "2017-07-11 16:36:28 xxxxx yyy" )), .Names = "c(NA)", row.names = c(NA, 6L), class = "data.frame")