'How can I change date formats in a column of a dataframe?

I'd like to change the format of an entire column in a dataframe in R. I saw answers for this in python, and I've been attempting all sorts of codes and trying, but nothing has worked. I've finally found a way to check and verify the value types of each column of my dataframe and the date column comes up as character. I'd like to change that to date. ...also, on another note, I've asked a few questions and people always say to put sample data in here, but I don't know how to copy my dataframe from RStudio cloud...? But I'll attempt to show some data and my codes.

data frame:

Id
ActivityDate
TotalSteps
TotalDistance
TrackerDistance
LoggedActivitiesDistance
VeryActiveDistance
ModeratelyActiveDistance
LightActiveDistance
SedentaryActiveDistance
VeryActiveMinutes
FairlyActiveMinutes
LightlyActiveMinutes
SedentaryMinutes
Calories
1
1503960366
4/12/2016
13162
8.50
8.50
0
1.88
0.55
6.06
0.00
25
13
328
728
1985
2
1503960366
4/13/2016
10735
6.97
6.97
0
1.57
0.69
4.71
0.00
21
19
217
776
1797
3
1503960366
4/14/2016
10460
6.74
6.74
0
2.44
0.40
3.91
0.00
30
11
181
1218
1776
4
1503960366
4/15/2016
9762
6.28
6.28
0
2.14
1.26
2.83
0.00
29
34
209
726
1745
5
1503960366
4/16/2016
12669
8.16
8.16
0
2.71
0.41
5.04
0.00
36
10
221
773
1863
6
1503960366
4/17/2016
9705
6.48
6.48
0
3.19
0.78
2.51
0.00
38
20
164
539
1728
7
1503960366
4/18/2016
13019
8.59
8.59
0
3.25
0.64
4.71
0.00
42
16
233
1149
1921
8
1503960366
4/19/2016
15506
9.88
9.88
0
3.53
1.32
5.03
0.00
50
31
264
775
2035
9
1503960366
4/20/2016
10544
6.68
6.68
0
1.96
0.48
4.24
0.00
28
12
205
818
1786
10
1503960366
4/21/2016
9819
6.34
6.34
0
1.34
0.35
4.65
0.00
19
8
211
838
1775
11
1503960366
4/22/2016
12764
8.13
8.13
0
4.76
1.12
2.24
0.00
66
27
130
1217
1827
12
1503960366
4/23/2016
14371
9.04
9.04
0
2.81
0.87
5.36
0.00
41
21
262
732
1949
13
1503960366
4/24/2016
10039
6.41
6.41
0
2.92
0.21
3.28
0.00
39
5
238
709
1788
14
1503960366
4/25/2016
15355
9.80
9.80
0
5.29
0.57
3.94
0.00
73
14
216
814
2013
15
1503960366
4/26/2016
13755
8.79
8.79
0

I don't know why it pastes like that. Anyways...

daily_activity <- read_csv("dailyActivity_merged.csv")

I then ran:

str(daily_activity)

To check what types of data each column was made of. I see my activity dates are chr types...which I looked up and saw meant characters. Is this correct? I used this same dataset in google sheets and double check it, there are 600 rows worth of each columns, and they came back with a ' in front of the numbers for dates, as if they were entered in distance measurements like the columns following the date column. This is incorrect obviously as this is a date, not a distance, so now I'd like to change the entire column to be dates.

I've tried:

as_date(daily_activity, ActivityDate)
mdy(ActivityDate)
help("mdy")
help("print")
help("str")

str(daily_activity) %>% as.date(ActivityDate,"mm/dd/yyyy")

Not sure what to do but there doesn't seem to be any site or reference for such a thing as I've been google-ing for answers and help for 2 days now.

2nd part of my quest, is to then use the newly created date column, and the already present Id column to merge two dataframes...is that possible? Both the dataframes have the date column that needs to be upgraded, and they both have the Id columns, so I was thinking a join statement...does that exist in R? Because I want to join both dataframes in their entirety, by matching up with both those columns, Id and date...but the other columns in the data frames are different, and I need to work with information from both dataframes, together.

Has any of this made sense? I hope so. I asked the questions as if I was talking to someone, like the recommend to do on this site. Thanks in advance for any advice, help or information.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source