0

I'm working in a project and I've the following problem:

I need to structure the data frame of a 1 month period with measures every 1 minute. It makes a column of 43.200 different dates. The thing is that my inputs have some missing data and instead of having always 43.200 measures, they have different sizes like 43.093, 42.928...

I want to replace the NA with the corresponding values, looking for them in the EQUIP variables I already have.

Any ideas of the best way to do it?

This is my first attemp, but is not working properly:

for (i in (1:length(fixed_df$ts))) {
  for (j in (1:length(EQUIP1$timestamp)))
    if (fixed_df$ts[i] == EQUIP1$timestamp[j]) {
      fixed_df$X1[i] <- EQUIP1$power[j]
    } else {
      fixed_df$X1[i] <- NA
    }
}

Thanks!

duckmayr
  • 16,303
  • 3
  • 35
  • 53
AlvaroRMS
  • 1
  • 1
  • Hi Alvaro, please edit your question to add a minimum reproducible example. When community members can quickly cut and paste a sample of your data into our own R sessions, and when you provide an example of the bad output you are getting along with specifically what you want the output to look like when the problem solved properly, more people will be able to propose solutions for you. Thanks :) – mysteRious Jun 13 '20 at 15:01
  • (1) I strongly suggest that having a date as a *column* is not a good idea. In general, I think having a column *name* that is also *data* (e.g., `2020-06-13` as a column name, even when converted into a "normal" column name in R-speak) is a bad idea. I suggest the data should be either transposed or pivoted from a "wide" format to a "long" format. (2) Given that, does https://stackoverflow.com/q/56187854/3358272 help? – r2evans Jun 13 '20 at 15:01
  • I've made some changes and added a couple of pictures, maybe it is easier to understand now what I want to do! – AlvaroRMS Jun 13 '20 at 15:40
  • Rather than providing images of your data, it is preferred to [edit] your question to include the output of the R command `dput(your_data)`, where `your_data` is the name of your dataset, or `dput(head(your_data))` when your data is large. Please see [How to make a great R reproducible example](https://stackoverflow.com/q/5963269/8386140) for more details. – duckmayr Jun 13 '20 at 16:00

0 Answers0