R, too much data in data.frame - r

I have problem with data in R. I'm loading data with:
data<-read.csv2("ceny_paliwo.csv", dec = ",")
data
an this is giving me:
X Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec
1 2014 5.32 5.34 5.34 5.27 5.29 5.23 5.29 5.22 5.19 5.17 4.98 4.75
2 2015 4.46 4.47 4.62 4.58 4.65 4.71 4.66 4.49 4.30 4.28 4.36 4.21
3 2016 3.87 3.73 3.86 3.90 4.07 4.23 4.17 4.10 4.26 4.35 4.32 4.53
4 2017 4.62 4.58 4.53 4.48 4.36 4.19 4.17 4.31 4.37 4.44 4.59 4.59
after this:
data2 <- round(unname(unlist(as.data.frame(data))), digits = 2)
data2
I'm receiving:
[1] 2014.00 2015.00 2016.00 2017.00 5.32 4.46 3.87 4.62 5.34 4.47 3.73 4.58 5.34
[14] 4.62 3.86 4.53 5.27 4.58 3.90 4.48 5.29 4.65 4.07 4.36 5.23 4.71
[27] 4.23 4.19 5.29 4.66 4.17 4.17 5.22 4.49 4.10 4.31 5.19 4.30 4.26
[40] 4.37 5.17 4.28 4.35 4.44 4.98 4.36 4.32 4.59 4.75 4.21 4.53 4.59
What I'm trying to do, is to don't have 2014.00 2015.00 2016.00 2017.00 this data in the first row.
Any idea how to do it?

Select only data from the second column like here:
data2 <- round(unname(unlist(as.data.frame(data[,c(2:ncol(data))]))), digits = 2)

Related

How can I subset my list to have only the last day of the month?

DGS1MO DGS3MO DGS1 DGS2 DGS3 DGS5 DGS7 DGS10 DGS20 DGS30
2001-07-31 3.67 3.54 3.53 3.79 4.06 4.57 4.86 5.07 5.61 5.51
2001-08-01 3.65 3.53 3.56 3.83 4.09 4.62 4.90 5.11 5.63 5.53
2001-08-02 3.65 3.53 3.57 3.89 4.17 4.69 4.97 5.17 5.68 5.57
2001-08-03 3.63 3.52 3.57 3.91 4.22 4.72 4.99 5.20 5.70 5.59
2001-08-06 3.62 3.52 3.56 3.88 4.17 4.71 4.99 5.19 5.70 5.59
2001-08-07 3.63 3.52 3.56 3.90 4.19 4.72 5.00 5.20 5.71 5.60
2001-08-08 3.61 3.49 3.46 3.77 4.05 4.61 4.87 4.99 5.61 5.52
2001-08-09 3.61 3.45 3.48 3.77 4.07 4.66 4.93 5.04 5.64 5.54
2001-08-10 3.58 3.43 3.45 3.73 4.03 4.61 4.88 4.99 5.61 5.52
2001-08-13 3.57 3.45 3.43 3.70 4.00 4.57 4.86 4.97 5.60 5.52
2001-08-14 3.54 3.43 3.46 3.74 4.03 4.59 4.87 4.97 5.61 5.51
2001-08-15 3.52 3.43 3.47 3.80 4.11 4.62 4.90 5.00 5.62 5.52
2001-08-16 3.48 3.39 3.43 3.75 4.04 4.58 4.84 4.95 5.58 5.48
2001-08-17 3.46 3.36 3.39 3.67 3.95 4.49 4.75 4.84 5.51 5.43
2001-08-20 3.48 3.42 3.44 3.74 4.02 4.55 4.81 4.91 5.55 5.46
2001-08-21 3.46 3.39 3.41 3.69 3.96 4.50 4.79 4.87 5.54 5.44
2001-08-22 3.46 3.38 3.44 3.76 4.03 4.53 4.81 4.91 5.53 5.44
2001-08-23 3.49 3.40 3.46 3.72 3.99 4.52 4.79 4.89 5.50 5.41
2001-08-24 3.49 3.42 3.48 3.76 4.03 4.55 4.82 4.93 5.54 5.45
2001-08-27 3.52 3.45 3.51 3.78 4.04 4.57 4.83 4.94 5.56 5.47
2001-08-28 3.53 3.41 3.46 3.71 3.97 4.48 4.73 4.85 5.49 5.41
2001-08-29 3.48 3.42 3.44 3.67 3.92 4.43 4.67 4.78 5.44 5.36
2001-08-30 3.41 3.36 3.38 3.61 3.88 4.42 4.68 4.79 5.45 5.37
2001-08-31 3.40 3.37 3.41 3.64 3.91 4.46 4.72 4.85 5.47 5.39
2001-09-04 3.43 3.44 3.55 3.83 4.10 4.63 4.88 4.99 5.59 5.50
2001-09-05 3.49 3.41 3.47 3.79 4.07 4.61 4.86 4.97 5.57 5.48
2001-09-06 3.44 3.34 3.40 3.65 3.93 4.48 4.73 4.86 5.50 5.41
2001-09-07 3.40 3.27 3.29 3.53 3.82 4.39 4.67 4.80 5.45 5.39
2001-09-10 3.40 3.26 3.31 3.53 3.82 4.41 4.69 4.84 5.50 5.43
2001-09-13 2.73 2.74 2.81 2.99 3.32 4.03 4.41 4.64 5.41 5.39
2001-09-14 2.54 2.64 2.73 2.87 3.17 3.92 4.31 4.57 5.38 5.35
2001-09-17 2.47 2.59 2.72 2.96 3.30 3.99 4.38 4.63 5.44 5.41
2001-09-18 2.34 2.48 2.69 2.96 3.31 4.01 4.46 4.72 5.59 5.55
2001-09-19 2.00 2.19 2.49 2.81 3.18 3.90 4.41 4.69 5.59 5.56
2001-09-20 2.04 2.22 2.56 2.91 3.27 3.97 4.47 4.75 5.67 5.62
2001-09-21 2.12 2.25 2.53 2.91 3.27 3.94 4.43 4.70 5.62 5.59
2001-09-24 2.38 2.38 2.56 2.94 3.30 4.00 4.47 4.73 5.61 5.58
2001-09-25 2.58 2.40 2.51 2.88 3.25 3.97 4.45 4.72 5.60 5.58
2001-09-26 2.51 2.38 2.48 2.82 3.18 3.91 4.39 4.65 5.52 5.50
2001-09-27 2.34 2.38 2.43 2.78 3.15 3.87 4.33 4.58 5.46 5.45
2001-09-28 2.28 2.40 2.49 2.86 3.22 3.93 4.37 4.60 5.45 5.42
2001-10-01 2.26 2.37 2.47 2.82 3.18 3.90 4.33 4.55 5.39 5.38
2001-10-02 2.27 2.26 2.43 2.77 3.14 3.87 4.31 4.53 5.36 5.34
2001-10-03 2.21 2.23 2.38 2.77 3.14 3.86 4.29 4.50 5.34 5.32
2001-10-04 2.22 2.21 2.37 2.75 3.14 3.88 4.29 4.53 5.33 5.31
2001-10-05 2.21 2.19 2.33 2.71 3.10 3.87 4.26 4.52 5.34 5.31
2001-10-09 2.24 2.22 2.35 2.74 3.16 3.96 4.35 4.62 5.42 5.39
Above I have my dataset that I am trying to subset. My goals is to subset the df to only include the last day of each month listed. For example 8/31/2021,9/27/2021...etc onward through the data.
I have been able to do specific dates but I need something that is dynamic.
Thanks in advance
With lubridate:
library(lubridate)
df$DAY <- as.Date(df$DAY)
df[df$DAY == ceiling_date(df$DAY,'month') - days(1),]
DAY DGS1MO DGS3MO DGS1 DGS2 DGS3 DGS5 DGS7 DGS10 DGS20 DGS30
1 2001-07-31 3.67 3.54 3.53 3.79 4.06 4.57 4.86 5.07 5.61 5.51
24 2001-08-31 3.40 3.37 3.41 3.64 3.91 4.46 4.72 4.85 5.47 5.39
df:
df <- read.table(text='
DAY DGS1MO DGS3MO DGS1 DGS2 DGS3 DGS5 DGS7 DGS10 DGS20 DGS30
2001-07-31 3.67 3.54 3.53 3.79 4.06 4.57 4.86 5.07 5.61 5.51
2001-08-01 3.65 3.53 3.56 3.83 4.09 4.62 4.90 5.11 5.63 5.53
2001-08-02 3.65 3.53 3.57 3.89 4.17 4.69 4.97 5.17 5.68 5.57
2001-08-03 3.63 3.52 3.57 3.91 4.22 4.72 4.99 5.20 5.70 5.59
2001-08-06 3.62 3.52 3.56 3.88 4.17 4.71 4.99 5.19 5.70 5.59
2001-08-07 3.63 3.52 3.56 3.90 4.19 4.72 5.00 5.20 5.71 5.60
2001-08-08 3.61 3.49 3.46 3.77 4.05 4.61 4.87 4.99 5.61 5.52
2001-08-09 3.61 3.45 3.48 3.77 4.07 4.66 4.93 5.04 5.64 5.54
2001-08-10 3.58 3.43 3.45 3.73 4.03 4.61 4.88 4.99 5.61 5.52
2001-08-13 3.57 3.45 3.43 3.70 4.00 4.57 4.86 4.97 5.60 5.52
2001-08-14 3.54 3.43 3.46 3.74 4.03 4.59 4.87 4.97 5.61 5.51
2001-08-15 3.52 3.43 3.47 3.80 4.11 4.62 4.90 5.00 5.62 5.52
2001-08-16 3.48 3.39 3.43 3.75 4.04 4.58 4.84 4.95 5.58 5.48
2001-08-17 3.46 3.36 3.39 3.67 3.95 4.49 4.75 4.84 5.51 5.43
2001-08-20 3.48 3.42 3.44 3.74 4.02 4.55 4.81 4.91 5.55 5.46
2001-08-21 3.46 3.39 3.41 3.69 3.96 4.50 4.79 4.87 5.54 5.44
2001-08-22 3.46 3.38 3.44 3.76 4.03 4.53 4.81 4.91 5.53 5.44
2001-08-23 3.49 3.40 3.46 3.72 3.99 4.52 4.79 4.89 5.50 5.41
2001-08-24 3.49 3.42 3.48 3.76 4.03 4.55 4.82 4.93 5.54 5.45
2001-08-27 3.52 3.45 3.51 3.78 4.04 4.57 4.83 4.94 5.56 5.47
2001-08-28 3.53 3.41 3.46 3.71 3.97 4.48 4.73 4.85 5.49 5.41
2001-08-29 3.48 3.42 3.44 3.67 3.92 4.43 4.67 4.78 5.44 5.36
2001-08-30 3.41 3.36 3.38 3.61 3.88 4.42 4.68 4.79 5.45 5.37
2001-08-31 3.40 3.37 3.41 3.64 3.91 4.46 4.72 4.85 5.47 5.39
2001-09-04 3.43 3.44 3.55 3.83 4.10 4.63 4.88 4.99 5.59 5.50
2001-09-05 3.49 3.41 3.47 3.79 4.07 4.61 4.86 4.97 5.57 5.48
2001-09-06 3.44 3.34 3.40 3.65 3.93 4.48 4.73 4.86 5.50 5.41
2001-09-07 3.40 3.27 3.29 3.53 3.82 4.39 4.67 4.80 5.45 5.39
2001-09-10 3.40 3.26 3.31 3.53 3.82 4.41 4.69 4.84 5.50 5.43
2001-09-13 2.73 2.74 2.81 2.99 3.32 4.03 4.41 4.64 5.41 5.39
2001-09-14 2.54 2.64 2.73 2.87 3.17 3.92 4.31 4.57 5.38 5.35
2001-09-17 2.47 2.59 2.72 2.96 3.30 3.99 4.38 4.63 5.44 5.41
2001-09-18 2.34 2.48 2.69 2.96 3.31 4.01 4.46 4.72 5.59 5.55
2001-09-19 2.00 2.19 2.49 2.81 3.18 3.90 4.41 4.69 5.59 5.56
2001-09-20 2.04 2.22 2.56 2.91 3.27 3.97 4.47 4.75 5.67 5.62
2001-09-21 2.12 2.25 2.53 2.91 3.27 3.94 4.43 4.70 5.62 5.59
2001-09-24 2.38 2.38 2.56 2.94 3.30 4.00 4.47 4.73 5.61 5.58
2001-09-25 2.58 2.40 2.51 2.88 3.25 3.97 4.45 4.72 5.60 5.58
2001-09-26 2.51 2.38 2.48 2.82 3.18 3.91 4.39 4.65 5.52 5.50
2001-09-27 2.34 2.38 2.43 2.78 3.15 3.87 4.33 4.58 5.46 5.45
2001-09-28 2.28 2.40 2.49 2.86 3.22 3.93 4.37 4.60 5.45 5.42
2001-10-01 2.26 2.37 2.47 2.82 3.18 3.90 4.33 4.55 5.39 5.38
2001-10-02 2.27 2.26 2.43 2.77 3.14 3.87 4.31 4.53 5.36 5.34
2001-10-03 2.21 2.23 2.38 2.77 3.14 3.86 4.29 4.50 5.34 5.32
2001-10-04 2.22 2.21 2.37 2.75 3.14 3.88 4.29 4.53 5.33 5.31
2001-10-05 2.21 2.19 2.33 2.71 3.10 3.87 4.26 4.52 5.34 5.31
2001-10-09 2.24 2.22 2.35 2.74 3.16 3.96 4.35 4.62 5.42 5.39',header=T)
A possible solution:
library(tidyverse)
library(lubridate)
df %>%
mutate(d = day(ymd(Date)), m = month(ymd(Date)), y = year(ymd(Date))) %>%
group_by(m, y) %>%
slice_max(d) %>%
ungroup %>%
select(-d, -m, -y)
#> # A tibble: 4 × 11
#> Date DGS1MO DGS3MO DGS1 DGS2 DGS3 DGS5 DGS7 DGS10 DGS20 DGS30
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2001-07-31 3.67 3.54 3.53 3.79 4.06 4.57 4.86 5.07 5.61 5.51
#> 2 2001-08-31 3.4 3.37 3.41 3.64 3.91 4.46 4.72 4.85 5.47 5.39
#> 3 2001-09-28 2.28 2.4 2.49 2.86 3.22 3.93 4.37 4.6 5.45 5.42
#> 4 2001-10-09 2.24 2.22 2.35 2.74 3.16 3.96 4.35 4.62 5.42 5.39
A date is the last of a month if and only if it is one day prior to the first of the following month. You can index the elements of a Date vector x satisfying this condition like so:
is_last_of_month <- function(x) {
x <- trunc(x)
x == as.Date(round(as.POSIXlt(x), units = "months")) - 1
}
x <- seq(as.Date("2022-02-24"), as.Date("2022-03-05"), by = 1)
x
## [1] "2022-02-24" "2022-02-25" "2022-02-26" "2022-02-27" "2022-02-28"
## [6] "2022-03-01" "2022-03-02" "2022-03-03" "2022-03-04" "2022-03-05"
is_last_of_month(x)
## [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
is_last_of_month operates on trunc(x) instead of x to defend against the possibility of fractional days, so that—for example—is_last_of_month(as.Date("2022-02-28") + u) is TRUE for all u greater than 0 but less than 1:
y <- as.Date("2022-02-28") + 0.5
y
## [1] "2022-02-28"
y == as.Date(round(as.POSIXlt(y), units = "months")) - 1
## [1] FALSE
is_last_of_month(y)
## [1] TRUE
(Well, "... for all u greater than 0 but less than 1" is not quite true in floating point arithmetic, but hopefully my meaning is clear.)

How to attach dates to Time Series in R

I would like to create a time series of dissolved oxygen levels over time at three different depths. Currently, I have my dates as a column in excel. When I run the data set through autoplot() I end up with four graphs consisting of time, top, middle, and bottom. I would like to have the top, middle and bottom graphs with time on the x axis.
TomDO<- ts(Tom_Frost_Dissolved_Oxygen)
autoplot(TomDO, ts.geom = 'ribbon', fill = 'blue')
Data: Tom_Frost_Dissolved_Oxygen
Top Middle Bottom Date
12.55 13.39 9.55 3/9/15
6.8 6.55 0.36 3/31/15
7.22 6.64 6.01 4/13/15
5.94 5.78 5.58 4/29/15
7.01 6.41 6.29 5/11/15
6.76 5.96 4.07 5/26/15
3.22 2.68 1.8 6/8/15
6.08 5.88 3.44 6/23/15
5.02 4.34 4.25 7/20/15
3.07 2.6 2.3 8/3/15
3.9 3.62 3.23 8/17/15
8.97 8.53 6.54 8/31/15
6.96 5.94 5.06 9/14/15
3.87 3.78 2.81 9/28/15
4.1 3.99 3.9 10/12/15
5.04 4.91 4.77 10/26/15
8.77 8.61 8.6 3/8/16
9.12 9.22 9.09 3/22/16
8.78 8.87 8.6 4/4/16
7.78 7.67 6.9 5/2/16
5.83 5.3 4.78 5/31/16
4.56 4.52 4.46 6/14/16
6.6 6.02 0.28 6/27/16
10.82 10.02 4.31 7/11/16
6.79 5.05 3.61 7/25/16
6.45 4.78 3.83 8/8/16
3.27 2.6 2.57 8/22/16
5.3 5.16 5.15 9/6/16
5.66 4.74 4.23 9/19/16
4.79 4.65 4.47 10/3/16
7.27 7.23 6.75 10/17/16
6.15 6.05 5.89 10/31/16
6.96 6.73 6.42 11/14/16
10.19 10.16 9.93 3/9/17
7.66 7.48 7.16 3/20/17
6.67 6.46 6.46 4/3/17
7.04 6.82 5.88 4/17/17
7.94 7.83 7.85 5/1/17
5.56 5.43 2.12 5/15/17
4.15 3.99 3.67 5/30/17
6.41 6.06 4.3 6/12/17
8.83 8.07 6.74 6/26/17
8.57 7.68 7.37 7/10/17
11.62 9.2 5.27 7/24/17
13.58 11.69 9.15 8/21/17
9.6 9.54 9.12 9/5/17
8.71 7.46 6.6 9/18/17
6.13 5.75 4.97 10/5/17
6.36 5.93 5.37 10/16/17
6.88 6.89 6.74 11/13/17
11.61 10.82 10.09 3/7/18
6.47 6.62 6.17 4/2/18
7.14 7.1 7.04 4/16/18
8.33 8.12 6.36 4/30/18
5.79 5.25 4.3 5/29/18
13.28 11.39 7.01 6/14/18
7.82 7.34 5.92 6/25/18
11.12 9.08 8.21 7/9/18
7.68 3.8 2.68 7/23/18
6.55 5.24 4.04 8/6/18
2.53 2.18 2.08 8/20/18
11.63 11.38 9.76 9/4/18
6.02 5.83 5.17 9/17/18
9.66 9.28 8.73 10/1/18
8.01 7.95 7.91 10/29/18
9.31 8.88 1.43 5/13/19
6.66 6.02 5.8 5/29/19
5.31 4.82 3.9 6/10/19
1.9 1.13 0.16 7/8/19
2.05 1.4 0.28 7/11/19
6.72 5.49 2.57 7/22/19
13.65 4.29 3.81 8/5/19
0.69 0 0 8/19/19
12.8 7.5 2.33 8/22/19
3.83 3.45 3.08 9/4/19
7.57 5.36 3.77 9/16/19
9.33 9.02 8.41 9/30/19
11.63 11.58 11.45 10/14/19
9.82 9.65 8.89 11/14/19
Using the tidyverse collection of package, you can get the expected plot by 1) setting date as a date format, 2) then reshape your data into a longer format using pivot_longer and plot it using ggplot and facet_wrap:
library(tidyverse)
df$Date <- as.Date(df$Date, format = "%m/%d/%Y")
df %>% pivot_longer(., -Date, names_to = "Var",values_to = "Val") %>%
ggplot(aes(x = Date))+
geom_ribbon(aes(ymin = 0, ymax = Val), fill = "blue")+
facet_wrap(Var~., ncol = 1)+
scale_x_date(date_breaks = "3 months", date_labels = "%b %Y")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Does it look what you are looking for ?

Assign columns to grouping variable for use with ordihull plotting

I have a dataframe consisting of dissimilarity ratings for pairs of 12 nations, and what I wish to do is essentially divide the columns (the nations) into three different groups (not combining their scores).
I am performing a non-metric multidimensional scaling, so I would like to plot the dissimilarity ratings with convex hulls according to these three groups.
I know the code for making the plots, all I am missing is the grouping variable that is needed, and I cannot for the life of me figure out how to create it.
Brazil Congo Cuba Egypt France India Israel Japan China UdSSR USA Yugoslavia
1 0.00 4.83 5.28 3.44 4.72 4.50 3.83 3.50 2.39 3.06 5.39 3.17
2 4.83 0.00 4.56 5.00 4.00 4.83 3.33 3.39 4.00 3.39 2.39 3.50
3 5.28 4.56 0.00 5.17 4.11 4.00 3.61 2.94 5.50 5.44 3.17 5.11
4 3.44 5.00 5.17 0.00 4.78 5.83 4.67 3.83 4.39 4.39 3.33 4.28
5 4.72 4.00 4.11 4.78 0.00 3.44 4.00 4.22 3.67 5.06 5.94 4.72
6 4.50 4.83 4.00 5.83 3.44 0.00 4.11 4.50 4.11 4.50 4.28 4.00
7 3.83 3.33 3.61 4.67 4.00 4.11 0.00 4.83 3.00 4.17 5.94 4.44
8 3.50 3.39 2.94 3.83 4.22 4.50 4.83 0.00 4.17 4.61 6.06 4.28
9 2.39 4.00 5.50 4.39 3.67 4.11 3.00 4.17 0.00 5.72 2.56 5.06
10 3.06 3.39 5.44 4.39 5.06 4.50 4.17 4.61 5.72 0.00 5.00 6.67
11 5.39 2.39 3.17 3.33 5.94 4.28 5.94 6.06 2.56 5.00 0.00 3.56
12 3.17 3.50 5.11 4.28 4.72 4.00 4.44 4.28 5.06 6.67 3.56 0.00
This is probably a frustratingly simple command, but I am truly lost.

Extract the column number which has the last data point from a table

I have the following inverted data frame
z
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
14 -8.70 0.28 18.66 4.81 -34.33 40.39 3.09 7.89 49.41
13 -6.10 9.51 -1.09 -0.01 7.89 -7.37 -0.61 -9.79 31.75 40.67 5.41 -10.53
12 -5.21 7.49 -7.92 3.54 11.19 -6.66 23.64 13.21 9.64 14.44 59.95 -20.96
11 -12.68 11.04 -11.10 -6.18 -5.61 8.93 94.99 30.15 14.37 31.08 -9.02 -14.77
10 5.07 -2.04 22.77 12.05 0.38 -3.28 -2.73 11.26 5.30 4.61 13.80 3.68
9 -0.82 0.86 3.18 1.06 6.47 1.57 2.25 -9.34 5.27 7.25 2.85 0.42
8 10.48 1.17 10.97 -0.13 0.32 -5.89 -2.26 -7.28 -1.39 3.35 14.81 3.40
7 -5.22 3.09 -7.75 -3.41 -0.09 12.37 -17.38 1.41 8.57 10.48 -1.20 7.45
6 13.85 7.22 3.14 -2.92 -7.12 0.45 3.51 -2.30 7.07 -2.83 -2.27 -1.52
5 -0.57 0.58 -2.59 3.29 -6.07 0.37 1.32 -0.58 4.07 -4.85 -0.48 1.66
4 0.46 -0.41 3.01 0.60 2.20 -2.39 0.22 3.99 5.50 16.07 -4.51 0.50
3 1.28 5.10 -3.61 5.02 3.04 -4.05 -2.64 1.88 -2.44 3.27 -2.71 2.02
2 -1.28 0.99 2.38 0.16 1.03 10.93 5.07 0.26 0.84 -0.05 -0.88 -3.71
1 2.33 -1.71 -0.41 -0.58 -2.19 1.26 1.88 -4.03 0.54 0.34 0.22 -0.50
I would like to find out which column has the last data point in this example -0.50 and extract the column name in this case Dec as a number (12), without using the -0.50 data point, tried wrong with the below expressions
which( colnames(z)==-0.50)
integer(0)
which( colnames(z)==z[length(z)])
integer(0)
Second example
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
18 -12.97 9.96 8.14
17 1.50 3.27 7.38 -1.63 8.53 2.97 1.51 10.99 4.51 -5.70 1.15 9.50
16 -1.38 3.61 -3.98 10.51 -8.39 5.29 -2.01 -3.47 -0.17 -6.20 13.93 9.04
15 -3.96 1.72 -3.28 2.06 -0.26 -1.27 -4.58 3.23 -7.76 2.09 7.33 16.81
14 4.38 0.56 7.09 -5.31 -2.61 -2.66 0.66 0.56 4.64 13.75 -7.10 -5.15
13 -10.13 -6.04 12.62 -3.76 -3.96 7.95 4.71 6.04 7.63 -7.96 -0.69 14.16
12 5.95 11.95 -10.80 2.45 10.19 -5.20 -0.68 0.62 0.26 4.72 -2.48 10.27
11 2.72 11.56 -0.80 -8.62 0.28 -2.96 1.33 3.09 5.14 4.03 6.37 -0.19
10 -5.38 6.58 4.64 -4.21 6.62 3.13 -1.85 7.63 -6.17 -2.95 7.32 -4.37
9 4.20 -2.58 4.01 5.66 -2.94 -1.17 -0.47 4.54 -1.10 1.48 3.24 2.14
8 3.86 -5.93 -3.95 6.46 5.05 1.91 -1.18 -0.88 6.99 2.52 2.42 0.24
7 3.85 7.95 -0.66 -0.99 1.99 5.06 -4.63 -3.00 -0.41 3.73 4.97 2.10
6 0.99 -0.21 -1.64 -3.01 -2.03 -1.26 -1.52 0.32 2.85 -1.59 5.12 -2.45
5 -2.64 2.33 4.91 1.75 -1.01 1.47 -2.78 4.78 0.94 2.51 -2.01 3.75
4 0.08 1.51 0.25 3.00 -2.16 -2.51 4.59 1.43 0.16 -2.59 0.97 1.65
3 0.63 -0.83 -0.68 0.12 -0.22 -3.17 4.41 -1.29 -2.18 -2.54 1.00 1.36
2 2.51 0.17 2.66 3.41 -2.40 -1.77 -0.63 -3.80 3.47 3.20 2.20 0.37
1 -2.37
Last point is Jan -2.37
Thanks
My answer is based on #BrodieG's one.
You could try nchar to test for "empty cells":
tail(which(nchar(as.matrix(z)) == 0, arr.ind=TRUE), 1)
col <- max(which(!is.na(t(as.matrix(z))))) %% ncol(z)
if(!col) col <- ncol(z)
names(z)[[col]]
# [1] "Dec"
This assumes "empty" values are NA, and that z is a data frame. I tested this by removing some values from the end, and it worked as well.

Plot multiple tables in a single plot

I have 11 time series which include a temperature column. In other words there are 11 tables which should be presented in a single plot with different lines in color or line type.
t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
4.14 4.12 4.09 4.07 4.14 4.14 4.12 4.09 4.07 5.70 42.67
4.01 3.99 3.97 3.94 4.01 4.01 3.99 3.97 3.94 4.14 39.98
3.89 3.86 3.84 3.82 3.89 3.89 3.86 3.84 3.82 4.01 38.73
3.77 3.74 3.72 3.69 3.77 3.77 3.74 3.72 3.69 3.89 37.50
3.64 3.62 3.59 3.57 3.64 3.64 3.62 3.59 3.57 3.77 36.25
3.52 3.50 3.48 3.45 3.52 3.52 3.50 3.48 3.45 3.64 35.07
3.40 3.38 3.35 3.33 3.40 3.40 3.38 3.35 3.33 3.52 33.86
3.27 3.24 3.22 3.19 3.27 3.27 3.24 3.22 3.19 3.40 32.52
3.13 3.10 3.07 3.05 3.13 3.13 3.10 3.07 3.05 3.27 31.11
2.99 2.96 2.94 2.91 2.99 2.99 2.96 2.94 2.91 3.13 29.73
2.85 2.81 2.78 2.75 2.85 2.85 2.81 2.78 2.75 2.99 28.23
2.69 2.66 2.63 2.59 2.69 2.69 2.66 2.63 2.59 2.85 26.69
2.53 2.49 2.46 2.42 2.53 2.53 2.49 2.46 2.42 2.69 25.01
2.36 2.33 2.29 2.26 2.36 2.36 2.33 2.29 2.26 2.53 23.36
2.19 2.16 2.13 2.10 2.19 2.19 2.16 2.13 2.10 2.36 21.74
2.05 2.02 1.98 1.95 2.05 2.05 2.02 1.98 1.95 2.19 20.24
One option is :
use melt to reshape data
ggplot2 to plot the melten data
dat$date <- seq(as.Date('2011-01-01'),as.Date('2011-01-31'),
length.out=dim(dat)[1])
library(reshape2)
dat.m <- melt(dat,id='date')
library(ggplot2)
qplot(data=subset(dat.m),x= date, y=value,color=variable, geom='line')
I remove the t11 variable from dataset and replot
qplot(data=subset(dat.m, variable != 't11'),x= date, y=value,
color=variable, geom='line')

Resources