Использования базы R Функция
Подобно тому, как альтернативная перспектива использования функции только базовые R
### Download the file
download.file("http://cdiac.ornl.gov/ftp/trends/co2/barrsio.co2",
"~/Downloads/so-data.txt")
### Read the data line by line
raw.dat <- readLines(file("~/Downloads/so-data.txt"))
### Extract the column names
col.names.index <- grep("jan.*feb", raw.dat, ignore.case=TRUE)
col.names <- raw.dat[col.names.index]
col.names <- strsplit(col.names, split='\t')[[1]]
(col.names <- col.names[-1])
### Extract the row names
row.names.index <- grep('^[12][019][0-9][0-9]', raw.dat)
row.names <- raw.dat[row.names.index]
row.names <- substr(row.names, 1, 4)
### Extract the data
data.rows.index <- row.names.index
data.rows <- raw.dat[row.names.index]
### I had to fix the first row of the data as it was missing a tab
### I don't know if this is true in the original file
data.rows[1] <- paste(data.rows[1],'\t')
### convert to a matrix
data.rows <-
matrix(as.numeric(unlist(strsplit(data.rows,
split='\t'))),
byrow=TRUE,
ncol=14)
### drop the first and last columns: rownames, ave.
data.rows <- data.rows[,-c(1,13)]
colnames(data.rows) <- col.names[-13]
rownames(data.rows) <- row.names
### Make the plots
par(mfrow=c(9,4))
par(mar=c(1,1,1,1)) ### prevents margins too large error
for (i in rownames(data.rows))
plot(data.rows[i,], type='l',main=i)
Участки следующим образом:
Вам удалось прочитать данные? – user20650
Вы хотите отображать уровни CO2 в течение всех месяцев в целом в зависимости от года? –