1
雖然努力的我data.frame
一列從字符串到日期對象轉換我有一個相當可怕的警告消息一起收到了意想不到的結果:
my_dataframe <- data.frame(date = c("20070610", "20170611"))
my_dataframe["date"] <- strptime(my_dataframe$date, format = "%Y%m%d")
# Warning message:
# In `[<-.data.frame`(`*tmp*`, "date", value = list(sec = c(NA_real_, :
# provided 11 variables to replace 1 variables
my_dataframe
# my_dataframe
# date
# 1 0
# 2 0
但是,如果我只是一個$<-.data.frame
操作我更換[<-.data.frame
操作收到我想要的結果,我不警告的任何問題:
my_dataframe <- data.frame(date = c("20070610", "20170611"))
my_dataframe$date <- strptime(my_dataframe$date, format = "%Y%m%d")
my_dataframe
# my_dataframe
# date
# 1 20070610
# 2 20170611
我現在做這種分析在一個完全不同的方式,但我覺得這種行爲差異實在令人痛心,並會如果有人湊真的很感激ld解釋它爲什麼會發生。
謝謝!
什麼是my_dataframe_1?這是一個錯字還是你在一個不同的數據框? – Marius
你有沒有學過幫助(「[」)? – Roland
我發現'help(「[。data.frame」)'更有用。 –