0

Thank you Andrew James. Your advice was insightful!

I would like to transform my data from 'DATASET A' to 'DATASET B', using R.

        DATASET A
country name Series Code 2011 2014 2017 2022
AFG ACTD 9.01 9.96 14.9 9.65
ALB ACTD 28.3 37.9 40.2 44.2
AFG FINTD 4.71 1.66 2.72 2.6
ALB 21.1 23.4 21.8 26.9 26.9
      DATASET B
country name Year ACTD FINTD
AFG 2011 9.01 4.71
AFG 2014 9.96 1.66
AFG 2017 14.9 2.72
AFG 2021 9.65 2.6
ALB 2011 28.3 23.4
ALB 2014 37.9 21.8
ALB 2017 40.2 26.9
ALB 2021 44.2 26.9

I have tried the following codes on my dataset named 'findat' and its transpose 'findat_t' but couldn't get results:

  1. findat<-cbind(findat_t[1:2], stack(findat[3:6]))

  2. findat_t<-cbind(findat_t[1:2], stack(findat_t[3:6]))

  3. library(data.table) dcast(data=setDT(findat),formula=ID~Series.Code, value.var="c(2011":"2021") findat

M.K
  • 1,464
  • 2
  • 24
  • 46
Alley
  • 1
  • Suggestions: (1) You should edit your [original question](https://stackoverflow.com/q/74837836/12567365) instead of creating a duplicate question here. (2) This question should be deleted. (3) Also, you can see that the tables are not formatted correctly, so take another look at that. (4) And the `r` tag is missing - but someone added it to your original question for you. – andrewJames Dec 18 '22 at 22:24

0 Answers0