Skip to content
Prev 5263 / 29559 Next

error "not a numeric vector" when use function "localG"

And if none of these helps remember to specify the NA (not available) values 
in your data 

read.table("data.txt", na.strings="yournavalues", as.is=TRUE)

If your NA values in the original data was for example "NN" R would think the 
column was all made of factors and thereby convert it. By using the as.is 
argument R will not try to anything smart, and you would than afterwords have 
to specify all columns as factors, numeric etc.

However, if you have given your NA values this should not be a problem. Try to 
make a txt file from the data below, and run the following code to get a 
better grip on what is happening when reading with read.table. Note the dot 
in row 5, column x6

date group x1 x2 x3 x4 x5 x6
02/20/1902 0 7 2.53 168.19 77.79 97.16 17.56
05/01/1920 0 5 2.87 175.25 57.83 157.14 18.73
05/22/1919 0 3 2.79 180.49 84.18 122.12 18.88
07/05/1902 0 7 2.38 165.98 58.74 96.51 9.35
12/03/1902 0 5 2.36 172.72 95.48 147 .
01/10/1914 0 6 2.69 180.33 89.13 131.49 16.88
03/13/1916 0 10 2.8 179.07 68.94 117.72 16.84
03/02/1915 0 10 3.27 170.17 78.69 159.61 26.41

ex1 <- read.table("asisex.txt", head=T, sep=" ", as.is=TRUE)
ex2 <- read.table("asisex.txt", head=T, sep=" ")
ex3<- read.table("asisex.txt", head=T, sep=" ", na.strings=".")
str(ex1)
str(ex2)
str(ex3)

Best wishes
Torleif
On Thursday 12 March 2009 10:16:01 pm Roger Bivand wrote: