[R] Long Format data
Jim Lemon
drj|m|emon @end|ng |rom gm@||@com
Thu Aug 5 11:53:17 CEST 2021
Hi Admire,
I think rep_n_stack in the prettyR package may do what you want:
# download and install the prettyR package
install.packages("prettyR")
# load the prettyR package
library(prettyR)
# read in your data
ATCdf<-read.csv("BOP_All_Countries.csv",stringsAsFactors=TRUE)
# convert the values you want to long format
ATClong<-rep_n_stack(ATCdf,to.stack=3:17,stack.names=c("year","value"))
# as your column names in Excel will be coerced to character values by
prepending "X",
# coerce them back to numeric
ATClong$year<-as.numeric(substr(ATClong$year,2,5))
# check the first row
ATClong[1,]
As the "Variables" column is messy, you may want to substitute the
numeric value in the long output and print a table of the numeric and
character values of the factor:
unique(ATClong$Variables)
ATClong$Variables<-as.numeric(ATClong$Variables)
Jim
On Tue, Aug 3, 2021 at 9:53 PM Admire Tarisirayi Chirume
<atchirume using gmail.com> wrote:
>
>
>
> Hello Jim, i hope you are well. I think my msg was rejected beacuse of the size of my files. I was kindly help me to structure data in the folder attached herewith in file BOP_All_Countries.csv. I am doing panel data analysis. I need it to be structured as it is on the file R_help.csv.
>
> Please kindly see the r-script below (r_help.R) that i ran which did not yield what i wanted.
>
> Thank you in advance for your help.
>
>
> Alternative email: addtarris using icloud.com/TChirume using rbz.co.zw
> Skype: admirechirume
> Call: +263773369884
> whatsapp: +818099861504
More information about the R-help
mailing list