Transpose a dataframe

Hi!

I have a data frame that has 17 variables: code (with 46 codes of stations of air measurement) and 16 variables that are years (from 2000 to 2015). I want to get a dataframe with two variables (code and year) from this dataframe. I tried transposing it, but it is not what I need.
image
What I want is like doing the contrary that the function spread from tidyr does.

Thanks in advance and happy 2020!!

The opposite of spread is not transposing, rather gather, also provided in tidyr package.

However, developments of both of these two functions are not continued in favour of pivot_longer and pivot_wider functions, available in the tidyr from version 1.0.0.

Try yourself with pivot_longer, and if you fail to solve your problem, please share a small part of the data set in a copy-paste friendly format.

In case you don't know how to do it, there are many options, which include:

  1. If you have stored the data set in some R object, dput function is very handy.

  2. In case the data set is in a spreadsheet, check out the datapasta package. Take a look at this link.

2 Likes

Thanks so much!!!!!! May you have a happy new year!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.