-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-data_reading_solution.R
58 lines (45 loc) · 1.94 KB
/
2-data_reading_solution.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # Read and write the main types of data files # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Just for Colin, do not run:
# server = livecode::serve_file()
# We will work with 3 different files:
# - "Data/rubis_01.txt"
# - "Data/population.csv"
# - "Data/FTIR_rocks.xlsx"
# Load them into separate `data.frames`.
# Look into the options of `read.table()`, `read.csv()`, `readxl::read_excel()`, to get the proper data fields.
# Make sure that the `rubis_01` data.frame has `w` and `intensity` as column names.
rubis_01 <- read.table("Data/rubis_01.txt", header=FALSE, col.names=c("w", "intensity"))
population <- read.csv("Data/population.csv")
FTIR_rocks <- readxl::read_excel("Data/FTIR_rocks.xlsx")
# Print their dimensions and column names.
dim(rubis_01)
dim(population)
dim(FTIR_rocks)
names(rubis_01)
names(population)
names(FTIR_rocks)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# We will use the TGA data file `"Data/ATG.txt"`
# Load it into a `data.frame`. Look into the options of [`read.table()`](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/read.table) to get the proper data fields.
# Hints:
# - check how many lines you have to read
# - check how many lines you have to skip before reading
# - you need to skip the line with the unit
d <- read.table("Data/ATG.txt",
skip = 10,
nrows = 4088,
header = TRUE,
comment.char = "["
)
head(d)
d <- read.table("Data/ATG.txt",
skip = 12,
nrows = 4088,
header = FALSE,
col.names = c("Index","t","Ts","Tr","Value")
)
head(d)