How to insert lines in specific locations in a data frame?

Asked

Viewed 507 times

0

I need to insert rows in the "Feb" column on days 30 and 31 that are filled in with "NA" so that the data contained in the rows is moved downwards. I tried to fev$novaLin <- with(fev, as.integer(d == 30, 31 & fev == NA, NA)), but it didn’t work because a column was created next to the column "Feb", with indication of Nas on the 30th and 31st and without the other data. As my data series is very long, I need a function that automates this process.

How can I fix this?

id dia fev 1 1 0.2 2 2 0.1 3 3 0 4 4 0 5 5 0.9 6 6 0.23 7 7 0 8 8 0 9 9 0 10 10 NA 11 11 NA 12 12 NA 13 13 NA 14 14 10.2 15 15 0 16 16 0 17 17 6.7 18 18 0 19 19 0 20 20 0 21 21 0 22 22 0.3 23 23 0.7 24 24 0 25 25 0 26 26 0 27 27 0 28 28 NA 29 29 NA 30 30 5.3 31 31 0 32 1 40.5 33 2 4.8 34 3 0

  • This is strange. Data for the days 30 and 31 February is a good indication that data or preprocessing are in trouble. But if so, what do you expect in response to the lines with id above 30?

  • Yes, the preprocessing is in trouble because I could not transpose my original dataframe properly, as I had shown in [https://answall.com/questions/288057/como-transpor-linhas-para-colunas-em-um-data-frame]. Therefore, I need to move the data from 30 and 31, because in fact they are from 01 and 02 next year.

  • 1

    Based on that reply I think you better dismiss this question and open a new question with the February data. It will be similar to the original question, but patience. Preferably instead of placing the table, put the result of the dput as the Sisters did in his answer. Continue processing this way this subject to propagate errors and it will be difficult for you to explain to someone what you have done.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.