Q:

Plot values of one certain row in different columns of a table

I have a huge table and I want to make a plot of lets say two different rows in this table.
Below you can see a small overview of my data set.
I want to plot now for country 4 the production of the years 1,2 and 3 so that someone can see the change over time
The same with country 6
On the X axis shoud be the years and on the  Y axis should be the values.
Can somebody help me?
Thanks in advance!
   country    year1        unit        year2        unit    year3
    1          5.1         tonnes       1.4         tonnes   5
    2          4.9         tonnes       1.4         tonnes   2
    3          4.7         tonnes       1.3         tonnes   3.5
    4          4.6         tonnes       1.5         tonnes   8
    5          5.0         tonnes       1.4         tonnes   8
    6          5.4         tonnes       1.7         tonnes   6

A:

These are the steps to create the plot.
The data:
dat <- read.table(text="country    year1      unit      year2      unit    year3
   1          5.1         tonnes       1.4         tonnes   5
   2          4.9         tonnes       1.4         tonnes   2
   3          4.7         tonnes       1.3         tonnes   3.5
   4          4.6         tonnes       1.5         tonnes   8
   5          5.0         tonnes       1.4         tonnes   8
   6          5.4         tonnes       1.7         tonnes   6", header = TRUE)

Choose a subset of the data:
subdat <- dat[dat$country == 4, c("year1", "year2", "year3")]

Arrange the data in the long format:
subdat_l <- data.frame(Value = unlist(subdat), Year = factor(1:3))

Plot:
plot(Value ~ Year, subdat_l)

If the actual data frame consists of the data of more than three years, you can use this general approach:
years <- grep("^year", names(dat), value = TRUE) # find the columns with the data
subdat <- dat[dat$country == 4, years]
subdat_l <- data.frame(Value = unlist(subdat),
                       Year = substr(years, 5, nchar(years)))

