"error in hist.default() : 'x' must be numeric"

Hello,

I would like to do an ENFA. For that I need to make a PCA and a histogram.
The data I have are location data ("locs" variable) and environmental variables data (exposure (=expo), slope (=pente), distance to the pond (=distmare) and land use (=osotheia) , all four are numerical variables).

> locs <- read.table("Loc_males_tris.txt", header = TRUE, sep="\t")
> locs
          x       y
1  965854.9 6906186
2  966196.7 6905950
3  965790.2 6906046
4  965832.9 6906141
5  965777.8 6906102
6  966150.7 6906081
7  966071.4 6906021
8  965833.9 6906141
9  965833.9 6906144
10 965720.2 6906552
11 965831.9 6906166
12 965738.6 6906048
13 965827.6 6906089
14 965753.3 6906043
15 965829.5 6906084
16 965829.5 6906084
17 965753.3 6906043
18 965837.7 6906081
19 965827.6 6906089
20 965827.4 6906088
21 965827.8 6906089
22 965831.8 6906083
23 965828.5 6906089
24 965847.4 6906084
25 965840.6 6906086
26 965507.1 6906314
27 965507.1 6906314
28 965494.8 6906081
29 965494.8 6906081
30 965668.5 6906120
31 965657.0 6906123
32 965507.1 6906314
33 965496.0 6906298
34 965497.6 6906297
35 965507.1 6906314
36 965832.8 6906202
37 965835.1 6906210
38 965905.2 6906162
39 965834.4 6906205
40 965834.2 6906202
41 965899.8 6906172
42 965955.0 6906226
43 965927.5 6906189
44 965832.4 6906200
45 965850.7 6906172
46 965842.4 6906214
47 965840.2 6906219
48 965841.2 6906214
49 965929.1 6906167
50 965929.1 6906167
51 965767.5 6906060
52 965767.5 6906060
53 965767.5 6906060
54 965767.5 6906060
55 965767.5 6906060
56 965767.5 6906060
57 965767.5 6906060
58 965794.9 6906092
59 965794.9 6906092
60 965788.7 6906113
61 965789.2 6906102
62 965794.9 6906092
63 965788.7 6906113
64 965787.1 6906102
65 966070.4 6906015
66 966086.6 6906024
67 966043.2 6906017
68 966046.7 6906023
69 966046.7 6906023
70 966087.5 6906019
71 966059.7 6906019
72 966046.7 6906023
73 966046.7 6906023
74 966177.7 6906077
75 966181.8 6906076
76 966180.8 6906076
77 966180.9 6906077
78 966181.4 6906077
79 966181.8 6906076
80 966046.7 6906023
81 966046.7 6906023
82 966171.6 6906080
83 966181.4 6906077
84 966116.9 6906037
85 966101.3 6906038
86 966096.1 6906033
87 966295.9 6905931
88 966288.0 6905935
89 966241.4 6905924
90 966120.3 6905997


> cartetot <- as.kasc(list(expo = carte1,
+                             pente = carte2,
+                             osotheia = carte3,
+                             distmare = carte4))
> cartetot
Raster map of class "kasc":
Cell size:  5 
Number of rows:  227 
Number of columns:  361 

Variables measured:
1. expo: numeric
2. pente: numeric
3. osotheia: numeric
4. distmare: numerictype or paste code here

My problem is that when I want to make the histogram, I get an error : "error in hist.default(enfa1, scores = FALSE, type ="l") : 'x' must be numeric".

here are my lines of codes:

dataenfa1 <- data2enfa(cartetot, locs)
dataenfa1
Data ENFA

 List of 4 elements:

  data.frame nrow  ncol content        
1 $tab       46933 4    table of pixels

  vector length content             
1 $pr    46933  vector of presence  
2 $index 46933  position of the rows

$attr: attributes of the initial kasc

pc <- dudi.pca(dataenfa1$tab, scannf = FALSE)
pc
Duality diagramm
class: pca dudi
$call: dudi.pca(df = dataenfa1$tab, scannf = FALSE)

$nf: 2 axis-components saved
$rank: 4
eigen values: 1.312 1.057 0.9473 0.6839
  vector length mode    content       
1 $cw    4      numeric column weights
2 $lw    46933  numeric row weights   
3 $eig   4      numeric eigen values  

  data.frame nrow  ncol content             
1 $tab       46933 4    modified array      
2 $li        46933 2    row coordinates     
3 $l1        46933 2    row normed scores   
4 $co        4     2    column coordinates  
5 $c1        4     2    column normed scores
other elements: cent norm 

enfa1 <- enfa(pc, dataenfa1$pr, scannf = FALSE)
enfa1
ENFA
$call: enfa(dudi = pc, pr = dataenfa1$pr, scannf = FALSE)

marginality: 1.382
eigen values of specialization: 1.828 1.038 0.7318
$nf: 1 axis of specialization saved

  vector length mode    content                              
1 $pr    46933  numeric vector of presence                   
2 $lw    46933  numeric row weights                          
3 $cw    4      numeric column weights                       
4 $mar   4      numeric coordinates of the marginality vector
5 $s     3      numeric eigen values of specialization       

  data.frame nrow  ncol content           
1 $tab       46933 4    modified array    
2 $li        46933 2    row coordinates   
3 $co        4     2    column coordinates

hist(enfa1,scores=FALSE,type="l")
Error in hist.default(enfa1, scores = FALSE, type = "l") : 
  'x' doit être numérique

So I don't understand why it doesn't work as all my variables are numeric.

Could you help me please ?
Thank's !

I don't know why you should be surprised: enfa1 is apparently a structure of some kind.
Try to extract the numeric vector that you are interested in from this structure and use hist on that part.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.