Using R, I'd like to combine into one column (date) the month nb (month) and the day nb (day) contained in two different columns and use the created column in a date format.
my data frame looks like this:
St Dep Month Day
A 2 1 1
B 2 1 1
B 2 2 1
A 5 1 1
A 7 1 1
C 2 1 1
C 5 1 1
And I want to add a column with something like "Jan-01".
Concatenate year, month and day to date with formulaSelect a blank cell to place the concatenated date, and enter formula =A2&"/"&B2&"/"&C2 into the formula bar, then press the Enter key. 2. Drag the populated cell's Fill Handle down to the cells for concatenating corresponding cells to date.
I assume here that by "date format" you just mean a string that looks like a date, rather than a proper date class in R.
data <- data.frame( Month=c(1,5,2), Day=c(1,2,3) )
data$MonthDay <- paste( month.abb[data$Month], data$Day, sep="-" )
data
# Month Day MonthDay
# 1 1 1 Jan-1
# 2 5 2 May-2
# 3 2 3 Feb-3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With