0

I have two excel files and I want to copy data row by row based on Column's values:

first file:

Id, X1, X2,......,Xn
1.11.2022, 10,20,....., 20
2.11.2022, 30, 40,....., 100
4.11.2022, 20, 30,......,70
.
30.11.2022, 10, 10,....., 50

as you can read in this file we do not have values of (3.11.2022)!!!!! the second file I created the same one with all days like

Id, X1, X2,......,Xn
1.11.2022, 
2.11.2022, 
3.11.2022, 
.
30.11.2022,

I want to write a code to read the first file row by row,

for i in file 1
for j in file 2
If i("ID")== j("ID")
write i with the same ID to J with the same ID
if j+1 = j +  one day to check if the sequence in j is correct.
else i = Na, Na, ....., Na
if we do not have value like day( 3.11.2022)

I know this matter is easier in other languages. It would be nice if someone can help me! Thanks in advance

How can I write the code of this process

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • 3
    Welcome to StackOverflow. Can you make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by providing relevant data using `dput()`? – jrcalabrese Nov 28 '22 at 15:38
  • Excel files ... are they `.xlsx` or `.csv`? Are you hoping to do with in R (the programming language, based on your [tag:r] tag) or you don't care? If in R, how are you reading them into R? If your "write i" is really just updating data in one of the tables, then this might be started by a merge/join operation. This question will be greatly improved with usable sample data (you can limit it to just a few rows/columns to get the point across). – r2evans Nov 28 '22 at 15:45
  • I think what you are asking is how to complete (fill in) missing dates, where the other columns will be `NA`. Please look at these three links, they have various methods/techniques for doing this with and without imputation of values: https://stackoverflow.com/q/66949481/3358272, https://stackoverflow.com/q/37691859/3358272, https://stackoverflow.com/q/33003819/3358272 – r2evans Nov 28 '22 at 15:51
  • Most of those rely on your "date" column (I think your `Id` is a date?) being a real date, not a string. That can be remedied with `dat$Id <- as.Date(dat$Id, format="%d.%m.%Y")`. From there, it should be easy enough to expand (`expand.grid` or `tidyr::complete`) and then merge/join (`merge(..)` or `dplyr::left_join(..)`). – r2evans Nov 28 '22 at 15:52

0 Answers0