1

I have a column like this: (I am using lubridate)

The S.D is a difference between order and ship date. It is gotten this way:

mutate(S.D = mdy(Ship.Date) - mdy(Order.Date))

 S.D
<time>

2 days
4 days
5 days
...

I want to convert it to:

 S.D
<int>

  2
  4
  5
...

How do I do that?

v_head
  • 759
  • 4
  • 13
  • 1
    There is some ambiguity in what you show. I'm inferring that you're using `dplyr` (or at least `tibble`), but it isn't obvious what package you're using that is providing the ` – r2evans Jan 03 '21 at 15:42
  • I did edit above – v_head Jan 03 '21 at 16:07
  • 1
    I'm glad you got an answer, but for next time ... your data is still unusable. (1) `mutate` takes as its first argument a `data.frame`, which your code does not include. (2) That notwithstanding, we also will see `object 'Ship.Date' not found`. I suggest you read https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info for a more detailed discussion of "reproducible" and "self-contained". – r2evans Jan 03 '21 at 17:04
  • 1
    ok, thanks, next time! – v_head Jan 03 '21 at 19:49

2 Answers2

2

What is your initial column format? Is it character, Date? I think you can try SD=as.integer(as.character(SD))

0

Assuming your column is in a data frame named df, you can use the parse_number() function in the readr package:

library(readr)
df$S.D <- parse_number(df$S.D)
SavedByJESUS
  • 3,262
  • 4
  • 32
  • 47
  • It doesn't work, it says: `Error in parse_vector(x, col_number(), na = na, locale = locale, trim_ws = trim_ws) : is.character(x) is not TRUE` – v_head Jan 03 '21 at 15:29
  • Would you please edit your question to include a chunk of your dataset? You can use: `dput(head(your_data_here))` – SavedByJESUS Jan 03 '21 at 15:49