简体   繁体   中英

CSV File Histogram Generator : 'x' must be numeric

Basically, I'm trying to get a visualization of a histogram using R. My dataset has a column of data with the first row value "data" the remaining data are all numeric values the problem is when use the hist() function I am unable to visualize the data.

I've already looked over the solutions:

Solution 1 Solution 2 Solution 3 Solution 4

My Data Set:

                 V1
1  \357\273\277data
2               256
3               256
4               256
5               256
6                64
7                64
8               128
9               128
10              128
11              128
12              128
13              128
14             1024
15             1024
16             1024
17             1024
18             1024
19             1024
20             1024
21             1024
22             1024
23             1024
24             1024
25             1024
26               32
27               32
28               32
29               32
30               32
31               32
32               32
33               32
34               32
35               32
36               32
37               32
38               32
39               32
40               32
41               32
42               32
43               32
44               32
45               32
46               32
47               32
48               32
49               32
50              512
51              512
52              512
53              512
54              512
55              512
56              512
57              512
58              512
59              512
60              512
61              512
62              512
63              512
64              512
65              512
66              512
67              512
68              512
69              512
70                2
71                2
72                2
73                2
74                2
75                2
76                2
77                2
78                2
79                2

Code :

TD2 = read.csv("/Users/somename/Desktop/TD.csv",head=TRUE)
TD2 -- Result above

Also Tried :

data <- read.table("/Users/somename/Desktop/TD.csv", sep="\t")
TDR = read.csv("/Users/somename/Desktop/TD.csv",header = FALSE,sep = ",")

Result :

hist(TD2)
Error in hist.default(TD2) : 'x' must be numeric

hist(data)
Error in hist.default(data) : 'x' must be numeric

hist(TDR)
Error in hist.default(TDR) : 'x' must be numeric

You need to read the data with stringsAsFactors set to FALSE . Then the plot can be obtained as follows:

hist(as.numeric(df[-1,]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM