I would like to transform this data to following
Asked
Active
Viewed 32 times
0

jrcalabrese
- 2,184
- 3
- 10
- 30

dk1
- 1
- 2
-
4It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. Please do not post an image of code/data/errors [for these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). Just include the data directly using e.g. `dput()`. – stefan Feb 23 '23 at 10:40
-
Please provide enough code so others can better understand or reproduce the problem. – Community Feb 23 '23 at 13:13
-
@stefan I will include code and data, thanks – dk1 Feb 23 '23 at 13:32
-
df <- data.frame(col1=c(NA,NA,NA,NA, 'A', 'B'), col2=c('year1', 'year2', 'year3', 'year4', 10,20)) #This should be converted to df1 <- data.frame(col1=c( 'A', 'B'), col2=c( 'year1', 'year1'), col3=c( 'year2', 'year2'), col4=c( 'year3', 'year3'), col5=c( 'year4', 'year4'), col6=c( 10, 20)) – dk1 Apr 05 '23 at 15:36