Re: [R] How to Reformat a dataframe

2023-10-28 Thread jim holtman
You can also use the pivot_longer to do it: library(tidyverse) input <- structure(list(...1 = c(92.9925354, 76.0024254, 44.99547465, 28.00536465, 120.0068103, 31.9980405, 85.0071837, 40.1532933, 19.3120917, 113.12581575, 28.45843425, 114.400074, 143.925, 46.439634, 20.7845679, 50.82874575,

Re: [R] How to Reformat a dataframe

2023-10-28 Thread avi.e.gross
Paul, I have snipped away your long message and want to suggest another approach or way of thinking to consider. You have received other good suggestions and I likely would have used something like that, probably within the dplyr/tidyverse but consider something simpler. You seem to be viewing

Re: [R] How to Reformat a dataframe

2023-10-28 Thread Rui Barradas
Às 04:13 de 28/10/2023, Paul Bernal escreveu: Dear friends, I have the following dataframe: dim(alajuela_df) [1] 126 12 dput(alajuela_df) structure(list(...1 = c(92.9925354, 76.0024254, 44.99547465, 28.00536465, 120.0068103, 31.9980405, 85.0071837, 40.1532933, 19.3120917, 113.12581575,

Re: [R] How to Reformat a dataframe

2023-10-28 Thread Chris Evans via R-help
The tidyverse idiom looks very different but does what you want and I have come to like it. What idiom of R one likes, for the mostly small datasets I handle, is largely a matter of preferenceds for "readability", itself very personal. Here's my tidyverse way of doing what you wanted: ###

Re: [R] How to Reformat a dataframe

2023-10-27 Thread Paul Bernal
Hi Iris, Thank you so much for your valuable feedback. I wonder why your code gives you 1512 rows, given that the original structure has 12 columns and 126 rows, so I would expect (125*12)+ 9=1,509 total rows. Cheers, Paul El El vie, 27 de oct. de 2023 a la(s) 10:40 p. m., Iris Simmons <

Re: [R] How to Reformat a dataframe

2023-10-27 Thread Iris Simmons
You are not getting the structure you want because the indexes are wrong. They should be something more like this: i <- 0 for (row in 1:nrow(alajuela_df)){ for (col in 1:ncol(alajuela_df)){ i <- i + 1 df[i,1]=alajuela_df[row,col] } } but I think what you are doing can be written much

[R] How to Reformat a dataframe

2023-10-27 Thread Paul Bernal
Dear friends, I have the following dataframe: dim(alajuela_df) [1] 126 12 dput(alajuela_df) structure(list(...1 = c(92.9925354, 76.0024254, 44.99547465, 28.00536465, 120.0068103, 31.9980405, 85.0071837, 40.1532933, 19.3120917, 113.12581575, 28.45843425, 114.400074, 143.925, 46.439634,