I need to remove commas from a field in an R dataframe. Technically I have managed to do this, but the result seems to be neither a vector nor a matrix, and I cannot get it back into the dataframe in a usable format. So is there a way to remove the commas from a field, AND have that field remain part of the dataframe.
Here is a sample of the field that needs commas removed, and the results generated by my code:
> print(x['TOT_EMP'])
TOT_EMP
1 132,588,810
2 6,542,950
3 2,278,260
4 248,760
> y
[1] "c(\"132588810\" \"6542950\" \"2278260\" \"248760\...)"
The desired result is a numeric field:
TOT_EMP
1 132588810
2 6542950
3 2278260
4 248760
x<-read.csv("/home/mark/Desktop/national_M2013_dl.csv",header=TRUE,colClasses="character")
y=(gsub(",","",x['TOT_EMP']))
print(y)