Hello I am trying to import a html table as data.frame and the columns come in as factors. I need to convert them to numeric, which I can do but when I use the single method it would take long and converting them to matrix trims the numbers. Can someone explain how to convert all the numbers in columns 2:6 into numerics that hold up the right numeric length?
nms = c("State/Territory", "FY 2008" ,"FY 2009", "FY 2010", "FY 2011", "FY 2012")
x <- data.frame(readHTMLTable('http://www.fns.usda.gov/pd/15SNAPpartPP.htm'), stringsAsFactors = F)
x <- x[5:57,]
names(x) <- nms
snap.partpp <- x
this is what i have tried to do to solve this problem but it does the conversion but changes the values of the numbers
x <- data.frame(readHTMLTable('http://www.fns.usda.gov/pd/15SNAPpartPP.htm'), stringsAsFactors = F)
y <- x[5:57, 1]
x <- data.matrix(x[5:57,2:6])
xy <- data.frame(y, x)
names(xy) <- nms
snap.avghh <- xy
The answer is in the comments, but is this what you had in mind?
Produces this: