Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting variables using dplyr

Tags:

r

dplyr

How I can convert variables using dplyr? Below code gives me:

All select() inputs must resolve to integer column positions.

mutate(superstore, Order.Date = as.Date(select(superstore, Order.Date)))

Data:

download.file('https://github.com/ywchiu/rcookbook/raw/master/chapter7/superstore_sales.csv', 'superstore_sales.csv')
like image 254
Testtest11 Avatar asked Jul 01 '26 17:07

Testtest11


1 Answers

I don't think you need to select the parameter you want to mutate. The code following would do (after you download the file to local directory):

library(read)
library(dplyr)
library(lubridate)
df <- read.csv("./superstore_sales.csv")
df <- mutate(df, Order.Date = as.Date(Order.Date))

Hope this could help.

like image 198
CSV Avatar answered Jul 03 '26 13:07

CSV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!