Question

I talked about this issue in another post but I didn't explain myself with clarity, apologizes, I'm new here. The problem that I have seems a bilge but I do not manage to see what I'm doing wrong. In first place I have this DatFrame in which there is a series of times in milliseconds, this dataframe can change in length, since the information is dynamic:

    ts
1   1393867136438
2   1393867136438
3   1393867136407
4   1393867136438
5   1393867136423
6   1393867136438
7   1393867136438

I have the following function in which I want to do this operation: I want to deduct to 1392217780000, each of the positions of the Dataframe "ts" previous, I will have X results depending on the size of the dataframe and I want to guard the results in a vector that then I pass to Dataframe.

get_ms_ts_list<-function(ts_list){
  ms_ts_list <- vector()
  static_num <- 1392217780000
  for (i in 1:length(ts_list[,1])){
    ms_ts_list[i] <- static_num-ts_list[i,1]
  }  
return(as.data.frame(ms_ts_list))
}

When I use this function I obtain these warnings and it generates me the dataframe that I've put here plenty of “Na’s”, I don't understand what I'm doing wrong ? Any idea ? thanks

Warning messages:
1: In Ops.factor(static_num, ts_list[i, 1]) : - not meaningful for factors
2: In Ops.factor(static_num, ts_list[i, 1]) : - not meaningful for factors
3: In Ops.factor(static_num, ts_list[i, 1]) : - not meaningful for factors
4: In Ops.factor(static_num, ts_list[i, 1]) : - not meaningful for factors
5: In Ops.factor(static_num, ts_list[i, 1]) : - not meaningful for factors
6: In Ops.factor(static_num, ts_list[i, 1]) : - not meaningful for factors
7: In Ops.factor(static_num, ts_list[i, 1]) : - not meaningful for factors



    ms_ts_list
1   NA
2   NA
3   NA
4   NA
5   NA
6   NA
7   NA

No correct solution

OTHER TIPS

ts_list is not a number. It is a factor. You can change it to a number by:

as.numeric(levels(ts_list))[ts_list] 

(details).

I have the answer

get_ms_ts_list<-function(ts_list){
  ms_ts_list <- vector()
  static_num <- 1392217780000
  #as.numeric(levels(ts_list))[ts_list]
  for (i in 1:length(ts_list[,1])){
    ms_ts_list[i] <- (static_num)-(as.numeric(as.character(ts_list[i,1])))
  }
  return(as.data.frame(ms_ts_list))
}

thanks anyway

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top