[R] how to add a calculated column into a data frame

Ravi Jeyaraman r@v|76 @end|ng |rom gm@||@com
Fri Jun 5 18:41:10 CEST 2020

How about something like this?

df <- data.frame(ID=1:3, DTVAL=c("2009-03-21","2010-05-11","2020-05-05"))

df <- df %>% mutate(YEAR = as.numeric(format(as.Date(DTVAL,'%Y-%m-%d'),

-----Original Message-----
From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of Charles Thuo
Sent: Friday, June 05, 2020 12:18 AM
To: r-help using r-project.org
Subject: [R] how to add a calculated column into a data frame

Dear  Sirs,

I have a data frame that has a column that shows the transaction date.

How do i add another column that  extracts the year of transaction from the
transaction date.


	[[alternative HTML version deleted]]

R-help using r-project.org <mailto:R-help using r-project.org>  mailing list -- To
UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

This email has been checked for viruses by AVG.

	[[alternative HTML version deleted]]

More information about the R-help mailing list