2
$\begingroup$

I have searched around but haven't found an answer to the following problem.

I have a spreadsheet with a large number of rows and 4 columns.

Column 3 contains dates not in a right format. So I want to convert column 3 to date objects and keep everything else.

data1 = {#[[1]],#[[2]],DateObject[#[[3]]],#[[4]]} & /@ Rest@data;

Here data is my imported data from the sheet.

My question: Assume that my sheet contains say 100 columns with Dates in column 37th.

How can I achieve the same thing as above?

$\endgroup$
2
  • 4
    $\begingroup$ MapAt[DateObject, yourData, {All, 37}] $\endgroup$
    – MarcoB
    Sep 30 at 22:07
  • $\begingroup$ @MarcoB Thank so much. This is exactly what I wanted. $\endgroup$
    – Jogn Bunda
    Sep 30 at 22:10
3
$\begingroup$

I'll convert my comment to an answer, just so that the question has one. You can use MapAt to apply a function at a specific location in a nested list:

MapAt[DateObject, yourData, {All, 37}]

This will apply the DateObject function to the 37th column of your data set.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.