-1

I have a csv file, with columns with numbers for e.g. 330789,340789 but in between there is a number with only 5 digits for e.g 41896.

I want to remove the first digit from every 6 digit number from the entire column.

How could I go about this?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 3
    Hi there, please look at this [guide how to ask good questions](https://stackoverflow.com/help/how-to-ask). At the Moment your question is too broad and does not include any or enough sample code. You probably will not get help because people around here do not like person's who try to free ride on their knowledge. Show some effort by asking a good questions and answers will follow. – Jan Oct 11 '18 at 07:49
  • You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to quickly create a reproducible example so others can help. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Oct 11 '18 at 08:20
  • Welcome to Stack Overflow! Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. But I think your question is still not answerable. **You** should [edit] your question now, to include your own efforts (see [help me is not a question](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) ). Feel free to drop me a comment in case you have further questions or feedback for me. – GhostCat Oct 11 '18 at 09:37

1 Answers1

0

If the column elements are 6-digit divide each element by 10^5. If column element is less than 6-digit then do nothing.

#let us say the data frame is df. column containing 6 digit numbers is col1

library(dplyr)

df <- df %>%
   mutate(
      col1 = ifelse((col1 / 100000) > 0 , col1%%100000,col1 )    
    )

print(df)
Anil Kumar
  • 385
  • 2
  • 17
  • 1
    I think you want `> 1`, not `> 0`. It'd also be more readable to use `1e5` instead of `100000`, much easier to tell t a glance that you're using the same number in both places. – Gregor Thomas Oct 11 '18 at 09:00
  • 1
    And on that note, why bother dividing at all? `col1 >= 1e5` is a nice simple condition to check. – Gregor Thomas Oct 11 '18 at 09:02