Skip to content
Prev 261833 / 398502 Next

Odp: Problem using read.xls - Everything converted to factors

Hi
"Firm","GDP1","GDP2","GDP3","GDP4","CPI5",
(character,character,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric)
Hm. That shall work. You have got some advice from Gabor but in case 
numeric columns come as non numeric I often find a problem with some kind 
of formating the original values. Numbers like 10 253,52 are treated as 
nonnumeric as there is extra space character between thousands and 
hundereds. Maybe also na.strings are not always marked as n.a. but 
sometimes the value is missing and I suppose this can lead to conversion 
of all column to character vector.
so on

you can spare some time to use sapply

testfile[,character columns] <- sapply(testfile[,character columns], 
as.numeric)

shall convert all character columns to numeric at once but you will get 
NAs to all values which could not be converted for any reason.

Regards
Petr
http://www.R-project.org/posting-guide.html