[問題] 讀取資料後的資料格式轉換
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
新手(沒寫過程式,R 是我的第一次)
[問題敘述]:
我用下面這行讀取資料
expenses <- read.csv("expenses.csv", stringsAsFactors=FALSE)
資料內欄位有字串也有數字與日期
但用str(expenses)查看時
所有欄位都顯示chr如下,不能做數字計算
'data.frame': 605 obs. of 7 variables:
$ Date : chr "1/22/2017" "1/13/2017" "1/22/2017" "2/19/2017" ...
$ Day : chr "22" "13" "22" "19" ...
$ Month : chr "Jan" "Jan" "Jan" "Feb" ...
$ Weekday : chr "Sunday" "Friday" "Sunday" "Sunday" ...
$ Amount : chr "3" "13" "15" "36" ...
$ Category: chr "Grooming and Health" "Grooming and Health" "Grooming and
Health" "Grooming and Health" ...
$ Comment : chr "Hajmola" "Crocin" "Digeine" "Sinarest" ...
我試了as.numeric(expenses$amount)
還是沒把格式改成numeric
整個卡住 ><
請問要怎麼做?
謝謝大家
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 76.85.38.120 (美國)
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1611425104.A.EB1.html
推
01/24 05:47,
4年前
, 1F
01/24 05:47, 1F
→
01/24 07:43,
4年前
, 2F
01/24 07:43, 2F
→
01/24 07:44,
4年前
, 3F
01/24 07:44, 3F
推
01/24 08:47,
4年前
, 4F
01/24 08:47, 4F
→
01/24 09:42,
4年前
, 5F
01/24 09:42, 5F
→
01/24 09:43,
4年前
, 6F
01/24 09:43, 6F
→
01/24 10:44,
4年前
, 7F
01/24 10:44, 7F
推
01/25 01:59,
4年前
, 8F
01/25 01:59, 8F
→
01/25 01:59,
4年前
, 9F
01/25 01:59, 9F
→
01/25 03:36,
4年前
, 10F
01/25 03:36, 10F
→
01/25 03:36,
4年前
, 11F
01/25 03:36, 11F
推
01/25 12:09,
4年前
, 12F
01/25 12:09, 12F
→
01/26 13:10,
4年前
, 13F
01/26 13:10, 13F
→
01/29 02:19,
4年前
, 14F
01/29 02:19, 14F
→
01/29 02:19,
4年前
, 15F
01/29 02:19, 15F
→
01/31 17:55,
4年前
, 16F
01/31 17:55, 16F
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章