Hi, I am an "R beginner", still getting my bearings.... please help.
I read in a csv as follows:
defense <- read.csv ("defense.csv", header=T, stringsAsFactors=F)
My issue is the dollar "amount" field was assigned "character" type, as follows:
str (defense)
'data.frame': 5024 obs. of 11 variables:
$ amount: chr "$548,277.00 " "$1,063,790.35 " "$2,988.72 "
I wish to change the "amount" field to numeric, so I can run meaningful aggregate functions i.e. the MEAN for the vector. I failed using the "as.numeric" and "type.convert", see following;
as.numeric ("defense$amount")
type.convert(defense$amount, na.strings = "NA", as.is = FALSE, dec = ".")
The str function still tells me that "amount" type is still "chr"
Any ideas? Thank you. Eli
I read in a csv as follows:
defense <- read.csv ("defense.csv", header=T, stringsAsFactors=F)
My issue is the dollar "amount" field was assigned "character" type, as follows:
str (defense)
'data.frame': 5024 obs. of 11 variables:
$ amount: chr "$548,277.00 " "$1,063,790.35 " "$2,988.72 "
I wish to change the "amount" field to numeric, so I can run meaningful aggregate functions i.e. the MEAN for the vector. I failed using the "as.numeric" and "type.convert", see following;
as.numeric ("defense$amount")
type.convert(defense$amount, na.strings = "NA", as.is = FALSE, dec = ".")
The str function still tells me that "amount" type is still "chr"
Any ideas? Thank you. Eli