0

I am facing one problem, I have a dataset which is for in and out time, column 1 to five is related to emid and dept. etc. from colum 6 to till end it has login data in the following format "02-01-15 16:56 ", I want to remove date and keep the time only. I have to exclude columns 1 to 5 and to format columns from 6 to last. so I am using lapply but I am facing following error.

emp_intime <- as.data.frame(lapply( emp_intime[, -1], as.POSIXlt))
Error in as.POSIXlt.numeric(X[[i]], ...) : 'origin' must be supplied


emp_intime <- as.data.frame(lapply( emp_intime[, -1], as.POSIXlt))
Error in as.POSIXlt.numeric(X[[i]], ...) : 'origin' must be supplied

I am getting an error, expected result is to remove the date from the every columns and leave only time.

Input Data:

structure(list(X = 1L, EmployeeID = 1L, Gender = "Female", Department = "Sales", YearsAtCompany = 1L, X01.01.15 = NA, X02.01.15 = "02-01-15 9:43", X05.01.15 = "05-01-15 10:08", X06.01.15 = "06-01-15 9:54", X07.01.15 = "07-01-15 9:34", X08.01.15 = "08-01-15 9:51", X09.01.15 = "09-01-15 10:09", X12.01.15 = "12-01-15 9:42", X13.01.15 = "13-01-15 10:13", X14.01.15 = NA, X15.01.15 = "15-01-15 10:01", X16.01.15 = "16-01-15 10:19", X19.01.15 = NA_character_, "), row.names = 1L, class = "data.frame") 
IceCreamToucan
  • 28,083
  • 2
  • 22
  • 38
dkv10
  • 1
  • 2
  • Please provide your input data, or a representative example, using `dput` – IceCreamToucan Nov 12 '19 at 14:09
  • input data is like EmployeeID Gender Department YearsAtCompany 01-01-15 02-01-15 05-01-15 06-01-15 07-01-15 08-01-15 09-01-15 12-01-15 13-01-15 14-01-15 15-01-15 16-01-15 1 Female Sales 1 NA 02-01-15 16:56 05-01-15 17:20 06-01-15 17:19 07-01-15 16:34 08-01-15 17:08 09-01-15 17:38 12-01-15 16:58 13-01-15 18:02 NA 15-01-15 17:22 16-01-15 17:35 – dkv10 Nov 12 '19 at 14:12
  • Please provide your input data, or a representative example, **using dput**. See [how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – IceCreamToucan Nov 12 '19 at 14:13
  • column name : EmployeeID Gender Department YearsAtCompany 01-01-15 02-01-15 05-01-15 06-01-15 07-01-15 08-01-15 09-01-15 12-01-15 13-01-15 14-01-15 1 1 Female Sales 1 NA 02-01-15 9:43 05-01-15 10:08 06-01-15 9:54 07-01-15 9:34 08-01-15 9:51 09-01-15 10:09 12-01-15 9:42 13-01-15 10:13 NA – dkv10 Nov 12 '19 at 14:15
  • You are not using dput. Please use dput, or provide some way to reproduce the error you get. The error is due to the class of your data, which cannot be seen when you copy and paste the printed output as in these comments. From SO Help: "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and **the shortest code necessary to reproduce it in the question itself.**" – IceCreamToucan Nov 12 '19 at 14:15
  • structure(list(X = 1L, EmployeeID = 1L, Gender = "Female", Department = "Sales", YearsAtCompany = 1L, X01.01.15 = NA, X02.01.15 = "02-01-15 9:43", X05.01.15 = "05-01-15 10:08", X06.01.15 = "06-01-15 9:54", X07.01.15 = "07-01-15 9:34", X08.01.15 = "08-01-15 9:51", X09.01.15 = "09-01-15 10:09", X12.01.15 = "12-01-15 9:42", X13.01.15 = "13-01-15 10:13", X14.01.15 = NA, X15.01.15 = "15-01-15 10:01", X16.01.15 = "16-01-15 10:19", X19.01.15 = NA_character_, "), row.names = 1L, class = "data.frame") – dkv10 Nov 12 '19 at 14:22
  • If you don't want to do your `lapply` on columns 1 through 5, maybe you want to `lapply` on `emp_intime[, -c(1:5)]` instead of just `-1`? Also, if you use `as.POSIXlt` would include `format` such as `%d-%m-%y %H:%M` (if 12-hr clock instead of 24-hour use `%I` instead of `%H`)...and much as been written about extracting only time from datetime objects...a lot depends on exactly what you plan to do...take a look at: https://stackoverflow.com/questions/9839343/extracting-time-from-posixct ... https://stackoverflow.com/questions/31876962/date-time-conversion-and-extract-only-time – Ben Nov 12 '19 at 16:53

0 Answers0