I am trying to convert my data from wide to long. I have an id variable and 131 columns of time data. All columns are integer format. The data was imported in csv format.
> class(ECGHR)
[1] "tbl_df" "tbl" "data.frame"
Here are the first 6 rows of data for 22 time-varying variables:
> head (ECGHR)
# A tibble: 6 × 132
id T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 T16 T17 T18 T19 T20 T21 T22
<int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
1 2003 70 65 69 71 68 74 67 65 60 66 59 99 74 73 87 94 88 88 98 73 72 63 79
2 2004 98 105 85 87 83 83 77 71 75 73 73 71 87 74 79 75 72 71 71 68 86 72 73
3 2008 93 92 91 90 93 88 89 83 93 96 95 94 89 91 87 93 88 100 93 92 89 93 83
4 2010 71 69 74 71 74 68 74 68 78 75 81 72 74 77 74 70 64 68 65 69 66 73 75
5 2018 90 86 93 91 86 82 97 95 95 83 79 88 78 92 86 94 83 79 96 91 72 78 80
6 2019 60 58 59 58 66 68 73 77 58 110 56 56 53 49 73 56 45 50 46 45 46 54 50
Here is my reshape code:
ECGHR_long=reshape(ECGHR, varying=c(2:132), direction="long", idvar="id", sep="")
Here is the warning message:
Error in 'row.names<-.data.frame'('tmp', value = paste(d[, idvar], times[1L], : invalid 'row.names' length In addition: Warning message: Setting row names on a tibble is deprecated.
I am used to working with data frames and I can't work out why it won't reshape (I'm new to R). Do I need to convert it to a dat frame? I'd be very grateful for any insights!