Kenny
Kenny

Reputation: 361

Turn numbers into integer with fread function when loading data

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

Upvotes: 0

Views: 632

Answers (1)

malin-fischer
malin-fischer

Reputation: 196

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.

Upvotes: 2

Related Questions