0

I used fread to load csv file as the following line.

data_startle <- fread('Materials/data/1/1.EMG.csv')

Figure 1 is what it looked like after loading into R and figure 2 is what it looked like in the file.

Can I make it the same in R as in EXCEL? All numbers in the last few columns should be integer.

Figure 1

enter image description here

Kenny
  • 361
  • 1
  • 8
  • Have you checked your input file with a text editor (such as Notepad)? Are you sure that they are integers? Are you also sure none of these values exceed the integer range? – Roland Jul 08 '21 at 09:03
  • @Roland Can I make numbers in R like 0001,000 as 1? I need to make it the same as in EXCEL to match my another data set. – Kenny Jul 08 '21 at 09:10
  • You can, but first define what “same” means to you. You should care about the internal representation of numbers but you seem to be focused on how numbers are displayed. Why is that? – Roland Jul 08 '21 at 09:15
  • Sorry I already assumed that there is a problem so haven't done my next step. So if 0001,000 and 1 mean the same to R, I am still able to match the two columns despite of different number display? – Kenny Jul 08 '21 at 09:23
  • R will coerce types as necessary. – Roland Jul 08 '21 at 10:11

1 Answers1

2

The fread function has an argument colClasses which you can use to specify data types of specific columns, e.g.:

data_startle <- fread('Materials/data/1/1.EMG.csv', colClasses=list(integer=c("practise","acq"))) 

See also this post for more details.