Convert to a Class Date but Add to a Data Frame Later On in R -


im trying add column existing data frame dates (2010-01-03, 2010-01-02, .. ), says day of week date (sunday, monday..). had issues converting "to class 'date'" , making column data frame instead of characters.

i got dataframe here (2009-01-03 2010-01-02)

chart_2009 <- read.csv('bchain-avbls (3).csv') chart_2009_days = data.frame(date=c(chart_2009[1])) chart_2009_days["2009 days of week"] <- na chart_2009_days[2] <- weekdays(as.date(chart_2009[1])) 

adding column data.frame simple as

## create dummy data.frame df <- data.frame(date = c("2010-01-03", "2010-01-02")) df #         date # 1 2010-01-03 # 2 2010-01-02  ## add new column df$newcolumn <- c("new", "column") df #         date newcolumn # 1 2010-01-03       new # 2 2010-01-02    column 

so there's no need create new object chart_2009_days, can append column directly

chart_2009$days <- weekdays(as.date(chart_2009[, 1])) 

noting it's better reference columns name, rather number, better

## haven't seen actual data i'm guessing column name here chart_2009$days <- weekdays(as.date(chart_2009[, "date_column"])) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -