Re: [R] Syntax help for 'Pivot_longer'
t;4.305900444, > > >3.616699448, > > >2.848148846, > > >2.016807672, > > >1.452876728, > > >2.120099832, > > >1.661317381, > > >1.133219897, > > >1.237239562, > > >0.93675648, > > >0.7379146, > > >1.026085605, > > >0.566766122, > > >0.13349775, > > >0.082892149, > > >15, > > >9, > > >1, > > >45, > > >44.5, > > >1018.5, > > >1 > > > ), > > > `20/03/2010` = c( > > >8.925945159, > > >7.375445078, > > >6.120095292, > > >5.608927408, > > >5.61367474, > > >4.83992, > > >4.216782177, > > >4.05288041, > > >3.779922823, > > >4.267840277, > > >3.747342619, > > >2.414025636, > > >2.647100163, > > >2.272566024, > > >2.526476424, > > >2.643863876, > > >1.290173713, > > >0.612263766, > > >0.465457136, > > >16, > > >10.5, > > >1, > > >67.5, > > >22, > > >1025, > > >1 > > > ), > > > `24/04/2011` = c( > > >6.278147269, > > >5.805619599, > > >5.149985946, > > >4.542354226, > > >4.320657374, > > >4.006103489, > > >3.642003696, > > >3.315992643, > > >3.181741995, > > >3.321634055, > > >2.814670223, > > >2.180686348, > > >2.253223258, > > >2.07198929, > > >1.912840489, > > >1.825988411, > > >1.360936689, > > >0.666152106, > > >0.537232782, > > >23, > > >19.5, > > >0, > > >191.25, > > >24.5, > > >1005.5, > > >1 > > > ) > > >), > > >row.names = c(NA, 26L), > > >class = "data.frame" > > > ) > > > > > ># Converts data table from wide (many columns) to long (many rows) and > > >creates the new object 'data_long' > > ># Column 1 is the 'Buffer' number (100-2000), Columns 2-25 contain > > >monthly data covering 2 years. > > ># Column headers for columns 2:25 are mutated into a column called > > >'Date', values for each buffer and each date into the column 'LST' > > > > > >data_long <- data %>% pivot_longer(cols = 2:25, names_pattern = names_to = > > > "Date", values_to = "LST") > > > > > ># Instructs R to treat the 'Date' column data as a date > > >data_long$Date <- as.Date(data_long$Date, format = "%d/%m/%Y") > > > > > ># Creates a new column called 'Month' by extracting the month number > > >from the date in the 'Date' column > > >data_long <- mutate(data_long, Month = format(data_long$Date, "%m")) > > > > > ># Creates a new column called 'Year' by extracting the Year number > > >( as %Y not %y) from the date in the 'Date' column > > >data_long <- mutate(data_long, Year = format(data_long$Date, "%Y")) > > > > > ># Creates a new column called 'JulianDay' by calculating the Julian > > >Day (day of the year from 1 January) from the date in the 'Date' > > >column. > > >data_long <- mutate(data_long, JulianDay = format(data_long$Date, "%j")) > > > > > ># Creates a new column called 'TimePeriod' where 1 = pre-construction, > > >and 2 = post-construction of solar park. > > ># Uses 'if_else' - If Year < 2015 value = 1, else 2. > > >data_long <- mutate(data_long, TimePeriod = if_else(data_long$Year < > > >2015, 1,2, missing = NULL)) > > > > > ># Instructs R to treat the 'TimePeriod' column as a (categorical) > > >factor - it is either 1 (pre-construction, or 2 (post-construction) > > >data_long$TimePeriod <- as.factor(data_long$TimePeriod) > > > > > ># Change data types of Month, Year nad JulianDay > > >data_long$Month <- as.num
Re: [R] Syntax help for 'Pivot_longer'
4/2011` = c( > >6.278147269, > >5.805619599, > >5.149985946, > >4.542354226, > >4.320657374, > >4.006103489, > >3.642003696, > >3.315992643, > >3.181741995, > >3.321634055, > >2.814670223, > >2.180686348, > >2.253223258, > >2.07198929, > >1.912840489, > >1.825988411, > >1.360936689, > >0.666152106, > >0.537232782, > >23, > >19.5, > >0, > >191.25, > >24.5, > >1005.5, > >1 > > ) > >), > >row.names = c(NA, 26L), > >class = "data.frame" > > ) > > > ># Converts data table from wide (many columns) to long (many rows) and > >creates the new object 'data_long' > ># Column 1 is the 'Buffer' number (100-2000), Columns 2-25 contain > >monthly data covering 2 years. > ># Column headers for columns 2:25 are mutated into a column called > >'Date', values for each buffer and each date into the column 'LST' > > > >data_long <- data %>% pivot_longer(cols = 2:25, names_pattern = names_to = > > "Date", values_to = "LST") > > > ># Instructs R to treat the 'Date' column data as a date > >data_long$Date <- as.Date(data_long$Date, format = "%d/%m/%Y") > > > ># Creates a new column called 'Month' by extracting the month number > >from the date in the 'Date' column > >data_long <- mutate(data_long, Month = format(data_long$Date, "%m")) > > > ># Creates a new column called 'Year' by extracting the Year number > >( as %Y not %y) from the date in the 'Date' column > >data_long <- mutate(data_long, Year = format(data_long$Date, "%Y")) > > > ># Creates a new column called 'JulianDay' by calculating the Julian > >Day (day of the year from 1 January) from the date in the 'Date' > >column. > >data_long <- mutate(data_long, JulianDay = format(data_long$Date, "%j")) > > > ># Creates a new column called 'TimePeriod' where 1 = pre-construction, > >and 2 = post-construction of solar park. > ># Uses 'if_else' - If Year < 2015 value = 1, else 2. > >data_long <- mutate(data_long, TimePeriod = if_else(data_long$Year < > >2015, 1,2, missing = NULL)) > > > ># Instructs R to treat the 'TimePeriod' column as a (categorical) > >factor - it is either 1 (pre-construction, or 2 (post-construction) > >data_long$TimePeriod <- as.factor(data_long$TimePeriod) > > > ># Change data types of Month, Year nad JulianDay > >data_long$Month <- as.numeric(data_long$Month) > >data_long$Year <- as.numeric(data_long$Year) > >data_long$JulianDay <- as.numeric(data_long$JulianDay) > > > ># 'Compactly display the internal structure of an R object' > >str(data_long) > > > ># Adds 'data_long' to R search path so that R can access it when > >evaluating a variable (simplifies syntax). > >attach(data_long) > > > > > >On Sun, 28 Nov 2021 at 15:59, Chris Evans wrote: > >> > >> Often the issue is that different variables in the wide format are of > >> different types so won't simply > >> pivot_longer without you making decisions which the function shouldn't > >> make for you. However, I think > >> the error messages when that happens are fairly clear so perhaps that's > >> not what's happening here. > >> > >> I'm happy to have a look at this as I've slowly become a convert to using > >> tidyverse principles and tools > >> (sometimes seen, legalistically correctly I think, as outside the remit of > >> this Email list) but I agree > >> that the help for pivot_longer() and many other tidyverse functions is not > >> as good as it could be particularly > >> for people new to R. Often there is better documentation in vignettes (so > >> look for that) or in other things > >> on the web. > >> > >> However, for me the data that was posted are mangled by the post coming in > >> HTML format. Please read the > >> list documentation and resubmit the question in raw text Email and submit > >> a bit of your data using > >> dput() (see ?dput and search out "R reproducible examples") and then I'll > >> look at it. > >> > >> Very best (all), > >> > >> Chris > >> > >
Re: [R] Syntax help for 'Pivot_longer'
long <- data %>% pivot_longer(cols = 2:25, names_pattern = names_to = > "Date", values_to = "LST") > ># Instructs R to treat the 'Date' column data as a date >data_long$Date <- as.Date(data_long$Date, format = "%d/%m/%Y") > ># Creates a new column called 'Month' by extracting the month number >from the date in the 'Date' column >data_long <- mutate(data_long, Month = format(data_long$Date, "%m")) > ># Creates a new column called 'Year' by extracting the Year number >( as %Y not %y) from the date in the 'Date' column >data_long <- mutate(data_long, Year = format(data_long$Date, "%Y")) > ># Creates a new column called 'JulianDay' by calculating the Julian >Day (day of the year from 1 January) from the date in the 'Date' >column. >data_long <- mutate(data_long, JulianDay = format(data_long$Date, "%j")) > ># Creates a new column called 'TimePeriod' where 1 = pre-construction, >and 2 = post-construction of solar park. ># Uses 'if_else' - If Year < 2015 value = 1, else 2. >data_long <- mutate(data_long, TimePeriod = if_else(data_long$Year < >2015, 1,2, missing = NULL)) > ># Instructs R to treat the 'TimePeriod' column as a (categorical) >factor - it is either 1 (pre-construction, or 2 (post-construction) >data_long$TimePeriod <- as.factor(data_long$TimePeriod) > ># Change data types of Month, Year nad JulianDay >data_long$Month <- as.numeric(data_long$Month) >data_long$Year <- as.numeric(data_long$Year) >data_long$JulianDay <- as.numeric(data_long$JulianDay) > ># 'Compactly display the internal structure of an R object' >str(data_long) > ># Adds 'data_long' to R search path so that R can access it when >evaluating a variable (simplifies syntax). >attach(data_long) > > >On Sun, 28 Nov 2021 at 15:59, Chris Evans wrote: >> >> Often the issue is that different variables in the wide format are of >> different types so won't simply >> pivot_longer without you making decisions which the function shouldn't make >> for you. However, I think >> the error messages when that happens are fairly clear so perhaps that's not >> what's happening here. >> >> I'm happy to have a look at this as I've slowly become a convert to using >> tidyverse principles and tools >> (sometimes seen, legalistically correctly I think, as outside the remit of >> this Email list) but I agree >> that the help for pivot_longer() and many other tidyverse functions is not >> as good as it could be particularly >> for people new to R. Often there is better documentation in vignettes (so >> look for that) or in other things >> on the web. >> >> However, for me the data that was posted are mangled by the post coming in >> HTML format. Please read the >> list documentation and resubmit the question in raw text Email and submit a >> bit of your data using >> dput() (see ?dput and search out "R reproducible examples") and then I'll >> look at it. >> >> Very best (all), >> >> Chris >> >> - Original Message - >> > From: "Philip Monk" >> > To: "R-help Mailing List" >> > Sent: Sunday, 28 November, 2021 13:57:07 >> > Subject: [R] Syntax help for 'Pivot_longer' >> >> > Hello, >> > >> > I have a wide table that I transform to a long table for analysis. >> > The wide table has 25 columns - the first is labels, then columns 2:25 >> > are monthly data of LST which is in 19 rows. >> > >> > I mutate this with : >> > >> > data_long <- data %>% pivot_longer(cols = 2:25, names_to = >> > "Date", values_to = "LST") >> > >> > I've decided to add some weather data which might be relevant, >> > inputting this as an additional 7 rows of data in the wide format (see >> > example below of the first 5 months of data). >> > >> > I have belatedly realised that I cannot work out how to pivot this >> > into the long format I need - the documentation doesn't provide enough >> > syntax examples for me to work it out (I've not long been using 'R'). >> > >> > How do I mutate this to provide the additional columns in the long >> > table for the weather variables? >> > >> > Thanks for your time, >> > >> > Philip >> > >> > Part-time PhD Student (Environmental Science) >> > Lancaster University, UK. >> > >> > >> > >>
Re: [R] Syntax help for 'Pivot_longer'
TimePeriod' where 1 = pre-construction, and 2 = post-construction of solar park. # Uses 'if_else' - If Year < 2015 value = 1, else 2. data_long <- mutate(data_long, TimePeriod = if_else(data_long$Year < 2015, 1,2, missing = NULL)) # Instructs R to treat the 'TimePeriod' column as a (categorical) factor - it is either 1 (pre-construction, or 2 (post-construction) data_long$TimePeriod <- as.factor(data_long$TimePeriod) # Change data types of Month, Year nad JulianDay data_long$Month <- as.numeric(data_long$Month) data_long$Year <- as.numeric(data_long$Year) data_long$JulianDay <- as.numeric(data_long$JulianDay) # 'Compactly display the internal structure of an R object' str(data_long) # Adds 'data_long' to R search path so that R can access it when evaluating a variable (simplifies syntax). attach(data_long) On Sun, 28 Nov 2021 at 15:59, Chris Evans wrote: > > Often the issue is that different variables in the wide format are of > different types so won't simply > pivot_longer without you making decisions which the function shouldn't make > for you. However, I think > the error messages when that happens are fairly clear so perhaps that's not > what's happening here. > > I'm happy to have a look at this as I've slowly become a convert to using > tidyverse principles and tools > (sometimes seen, legalistically correctly I think, as outside the remit of > this Email list) but I agree > that the help for pivot_longer() and many other tidyverse functions is not as > good as it could be particularly > for people new to R. Often there is better documentation in vignettes (so > look for that) or in other things > on the web. > > However, for me the data that was posted are mangled by the post coming in > HTML format. Please read the > list documentation and resubmit the question in raw text Email and submit a > bit of your data using > dput() (see ?dput and search out "R reproducible examples") and then I'll > look at it. > > Very best (all), > > Chris > > - Original Message - > > From: "Philip Monk" > > To: "R-help Mailing List" > > Sent: Sunday, 28 November, 2021 13:57:07 > > Subject: [R] Syntax help for 'Pivot_longer' > > > Hello, > > > > I have a wide table that I transform to a long table for analysis. > > The wide table has 25 columns - the first is labels, then columns 2:25 > > are monthly data of LST which is in 19 rows. > > > > I mutate this with : > > > > data_long <- data %>% pivot_longer(cols = 2:25, names_to = > > "Date", values_to = "LST") > > > > I've decided to add some weather data which might be relevant, > > inputting this as an additional 7 rows of data in the wide format (see > > example below of the first 5 months of data). > > > > I have belatedly realised that I cannot work out how to pivot this > > into the long format I need - the documentation doesn't provide enough > > syntax examples for me to work it out (I've not long been using 'R'). > > > > How do I mutate this to provide the additional columns in the long > > table for the weather variables? > > > > Thanks for your time, > > > > Philip > > > > Part-time PhD Student (Environmental Science) > > Lancaster University, UK. > > > > > > > > Wide data > > -- > > > > Buffer15/01/2010 16/02/2010 20/03/2010 > > 24/04/2011 07/05/2010 > > > > 1006.091741043 6.405879111 8.925945159 > > 6.278147269 6.133940129 > > > > 2005.271975614 5.994054977 7.375445078 > > 5.805619599 5.537759202 > > > > 3004.451891901 5.61142085 6.120095292 > > 5.149985946 5.353001442 > > > > 4003.385694303 4.77953426 5.608927408 > > 4.542354226 4.824773827 > > > > 5002.900508112 4.305900444 5.61367474 > > 4.320657374 4.520022189 > > > > 6003.110238149 3.616699448 4.83992 > > 4.006103489 4.188421662 > > > > 700 3.150580922 2.848148846 4.216782177 > > 3.642003696 3.725611032 > > > > 800 3.079728958 2.016807672 4.05288041 > > 3.315992643 3.278124347 > > > > 900 2.327902499 1.452876728 3.779922823 > > 3.181741995 3.29577819 > > > > 1000 1.641887823 2.120099832 4.267840277 > > 3.321634055 3.551965361 > > > > 1100 1.63370882 1.661317381 3.7
Re: [R] Syntax help for 'Pivot_longer'
Sighh... Questions on "non-standard" packages such as the TidyVerse universe are off topic here: per the posting guide: "If the question relates to a contributed package , e.g., one downloaded from CRAN, try contacting the package maintainer first. You can also use find("functionname") and packageDescription("packagename") to find this information. Only send such questions to R-help or R-devel if you get no reply or need further assistance. This applies to both requests for help and to bug reports." More to the point, RStudio has its own Help site for these questions: https://www.tidyverse.org/help/ ## and, in particular, https://community.rstudio.com/ Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Nov 28, 2021 at 5:57 AM Philip Monk wrote: > > Hello, > > I have a wide table that I transform to a long table for analysis. > The wide table has 25 columns - the first is labels, then columns 2:25 > are monthly data of LST which is in 19 rows. > > I mutate this with : > > data_long <- data %>% pivot_longer(cols = 2:25, names_to = > "Date", values_to = "LST") > > I've decided to add some weather data which might be relevant, > inputting this as an additional 7 rows of data in the wide format (see > example below of the first 5 months of data). > > I have belatedly realised that I cannot work out how to pivot this > into the long format I need - the documentation doesn't provide enough > syntax examples for me to work it out (I've not long been using 'R'). > > How do I mutate this to provide the additional columns in the long > table for the weather variables? > > Thanks for your time, > > Philip > > Part-time PhD Student (Environmental Science) > Lancaster University, UK. > > > > Wide data > -- > > Buffer15/01/2010 16/02/2010 20/03/2010 > 24/04/2011 07/05/2010 > > 1006.091741043 6.405879111 8.925945159 > 6.278147269 6.133940129 > > 2005.271975614 5.994054977 7.375445078 > 5.805619599 5.537759202 > > 3004.451891901 5.61142085 6.120095292 > 5.149985946 5.353001442 > > 4003.385694303 4.77953426 5.608927408 > 4.542354226 4.824773827 > > 5002.900508112 4.305900444 5.61367474 > 4.320657374 4.520022189 > > 6003.110238149 3.616699448 4.83992 > 4.006103489 4.188421662 > > 700 3.150580922 2.848148846 4.216782177 > 3.642003696 3.725611032 > > 800 3.079728958 2.016807672 4.05288041 > 3.315992643 3.278124347 > > 900 2.327902499 1.452876728 3.779922823 > 3.181741995 3.29577819 > > 1000 1.641887823 2.120099832 4.267840277 > 3.321634055 3.551965361 > > 1100 1.63370882 1.661317381 3.747342619 > 2.814670223 2.807355369 > > 1200 0.986559368 1.133219897 2.414025636 > 2.180686348 2.166547946 > > 1300 0.920601397 1.237239562 2.647100163 > 2.253223258 2.411947081 > > 1400 0.571882394 0.93675648 2.272566024 > 2.07198929 1.954723088 > > 1500 0.340505009 0.7379146 2.526476424 > 1.912840489 2.003872651 > > 1600 0.813480877 1.026085605 2.643863876 > 1.825988411 2.278799668 > > 1700 0.47192 0.566766122 1.290173713 > 1.360936689 1.45967449 > > 1800 0.269067515 0.13349775 0.612263766 > 0.666152106 0.680354177 > > 1900 0.303179244 0.082892149 0.465457136 > 0.537232782 0.287185161 > > Temperautre 1215 16 > 23 21.5 > > Wind speed 109 10.5 > 9.5 9.5 > > Wind trend 1 1 1 > 0 1 > > Wind direction 22.545 67.5 > 191.2556.25 > > Humidity 40 44.5 22 > 24.57 > > Pressure 1024 1018.5 1025 >1005.51015.5 > > Pressure trend 1 11 >1 1 > > > > > long data > - > Buffer Date LST Temperature Wind > speed .. > 1 01.01.21 4 510 > 2 01.02.21 5 211 > 3 01.03.21 7 515 > 4 01.04.21 9 67 > 5 01.05.21 7
Re: [R] Syntax help for 'Pivot_longer'
Often the issue is that different variables in the wide format are of different types so won't simply pivot_longer without you making decisions which the function shouldn't make for you. However, I think the error messages when that happens are fairly clear so perhaps that's not what's happening here. I'm happy to have a look at this as I've slowly become a convert to using tidyverse principles and tools (sometimes seen, legalistically correctly I think, as outside the remit of this Email list) but I agree that the help for pivot_longer() and many other tidyverse functions is not as good as it could be particularly for people new to R. Often there is better documentation in vignettes (so look for that) or in other things on the web. However, for me the data that was posted are mangled by the post coming in HTML format. Please read the list documentation and resubmit the question in raw text Email and submit a bit of your data using dput() (see ?dput and search out "R reproducible examples") and then I'll look at it. Very best (all), Chris - Original Message - > From: "Philip Monk" > To: "R-help Mailing List" > Sent: Sunday, 28 November, 2021 13:57:07 > Subject: [R] Syntax help for 'Pivot_longer' > Hello, > > I have a wide table that I transform to a long table for analysis. > The wide table has 25 columns - the first is labels, then columns 2:25 > are monthly data of LST which is in 19 rows. > > I mutate this with : > > data_long <- data %>% pivot_longer(cols = 2:25, names_to = > "Date", values_to = "LST") > > I've decided to add some weather data which might be relevant, > inputting this as an additional 7 rows of data in the wide format (see > example below of the first 5 months of data). > > I have belatedly realised that I cannot work out how to pivot this > into the long format I need - the documentation doesn't provide enough > syntax examples for me to work it out (I've not long been using 'R'). > > How do I mutate this to provide the additional columns in the long > table for the weather variables? > > Thanks for your time, > > Philip > > Part-time PhD Student (Environmental Science) > Lancaster University, UK. > > > > Wide data > -- > > Buffer15/01/2010 16/02/2010 20/03/2010 > 24/04/2011 07/05/2010 > > 1006.091741043 6.405879111 8.925945159 > 6.278147269 6.133940129 > > 2005.271975614 5.994054977 7.375445078 > 5.805619599 5.537759202 > > 3004.451891901 5.61142085 6.120095292 > 5.149985946 5.353001442 > > 4003.385694303 4.77953426 5.608927408 > 4.542354226 4.824773827 > > 5002.900508112 4.305900444 5.61367474 > 4.320657374 4.520022189 > > 6003.110238149 3.616699448 4.83992 > 4.006103489 4.188421662 > > 700 3.150580922 2.848148846 4.216782177 > 3.642003696 3.725611032 > > 800 3.079728958 2.016807672 4.05288041 > 3.315992643 3.278124347 > > 900 2.327902499 1.452876728 3.779922823 > 3.181741995 3.29577819 > > 1000 1.641887823 2.120099832 4.267840277 > 3.321634055 3.551965361 > > 1100 1.63370882 1.661317381 3.747342619 > 2.814670223 2.807355369 > > 1200 0.986559368 1.133219897 2.414025636 > 2.180686348 2.166547946 > > 1300 0.920601397 1.237239562 2.647100163 > 2.253223258 2.411947081 > > 1400 0.571882394 0.93675648 2.272566024 > 2.07198929 1.954723088 > > 1500 0.340505009 0.7379146 2.526476424 > 1.912840489 2.003872651 > > 1600 0.813480877 1.026085605 2.643863876 > 1.825988411 2.278799668 > > 1700 0.47192 0.566766122 1.290173713 > 1.360936689 1.45967449 > > 1800 0.269067515 0.13349775 0.612263766 > 0.666152106 0.680354177 > > 1900 0.303179244 0.082892149 0.465457136 > 0.537232782 0.287185161 > > Temperautre 1215 16 > 23 21.5 > > Wind speed 109 10.5 > 9.5 9.5 > > Wind trend 1 1 1 >0 1 > > Wind direction 22.545 67.5 > 191.2556.25 > > Humidity 40 44.5
Re: [R] Syntax help for 'Pivot_longer'
Hi! If I understood this correctly, you want to pivot the columns from 2 to 25 and use the first column as a "key". Your data has 27 columns in total, right? I tested it with your data and seems that the parameter 'cols' does have some problems. It takes all variables irrespectively of the range defined. I tired it with '2:25', '2:10' etc. and always the columns nor included in 'cols' are present in the long table as separate columns. Could this be an error in the function? Or can someone from the list explain this, in my eyes a bit unlogical behaviour... Best, Kimmo su, 2021-11-28 kello 13:57 +, Philip Monk kirjoitti: > Hello, > > I have a wide table that I transform to a long table for analysis. > The wide table has 25 columns - the first is labels, then columns > 2:25 > are monthly data of LST which is in 19 rows. > > I mutate this with : > > data_long <- data %>% pivot_longer(cols = 2:25, names_to = > "Date", values_to = "LST") > > I've decided to add some weather data which might be relevant, > inputting this as an additional 7 rows of data in the wide format > (see > example below of the first 5 months of data). > > I have belatedly realised that I cannot work out how to pivot this > into the long format I need - the documentation doesn't provide > enough > syntax examples for me to work it out (I've not long been using 'R'). > > How do I mutate this to provide the additional columns in the long > table for the weather variables? > > Thanks for your time, > > Philip > > Part-time PhD Student (Environmental Science) > Lancaster University, UK. > > > > Wide data > -- > > Buffer15/01/2010 16/02/2010 20/03/2010 > 24/04/2011 07/05/2010 > > 1006.091741043 6.405879111 8.925945159 > 6.278147269 6.133940129 > > 2005.271975614 5.994054977 7.375445078 > 5.805619599 5.537759202 > > 3004.451891901 5.61142085 6.120095292 > 5.149985946 5.353001442 > > 4003.385694303 4.77953426 5.608927408 > 4.542354226 4.824773827 > > 5002.900508112 4.305900444 5.61367474 > 4.320657374 4.520022189 > > 6003.110238149 3.616699448 4.83992 > 4.006103489 4.188421662 > > 700 3.150580922 2.848148846 4.216782177 > 3.642003696 3.725611032 > > 800 3.079728958 2.016807672 4.05288041 > 3.315992643 3.278124347 > > 900 2.327902499 1.452876728 3.779922823 > 3.181741995 3.29577819 > > 1000 1.641887823 2.120099832 4.267840277 > 3.321634055 3.551965361 > > 1100 1.63370882 1.661317381 3.747342619 > 2.814670223 2.807355369 > > 1200 0.986559368 1.133219897 2.414025636 > 2.180686348 2.166547946 > > 1300 0.920601397 1.237239562 2.647100163 > 2.253223258 2.411947081 > > 1400 0.571882394 0.93675648 2.272566024 > 2.07198929 1.954723088 > > 1500 0.340505009 0.7379146 2.526476424 > 1.912840489 2.003872651 > > 1600 0.813480877 1.026085605 2.643863876 > 1.825988411 2.278799668 > > 1700 0.47192 0.566766122 1.290173713 > 1.360936689 1.45967449 > > 1800 0.269067515 0.13349775 0.612263766 > 0.666152106 0.680354177 > > 1900 0.303179244 0.082892149 0.465457136 > 0.537232782 0.287185161 > > Temperautre 1215 16 > 23 21.5 > > Wind speed 109 10.5 > 9.5 9.5 > > Wind trend 1 1 1 > 0 1 > > Wind direction 22.545 67.5 > 191.2556.25 > > Humidity 40 44.5 22 > 24.57 > > Pressure 1024 1018.5 1025 >1005.51015.5 > > Pressure trend 1 11 >1 1 > > > > > long data > - > Buffer Date LST Temperature Wind > speed .. > 1 01.01.21 4 5 >10 > 2 01.02.21 5 2 >11 > 3 01.03.21 7 5 >15 > 4 01.04.21 9 6 >7 > 5 01.05.21 7 5 >10 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help >
[R] Syntax help for 'Pivot_longer'
Hello, I have a wide table that I transform to a long table for analysis. The wide table has 25 columns - the first is labels, then columns 2:25 are monthly data of LST which is in 19 rows. I mutate this with : data_long <- data %>% pivot_longer(cols = 2:25, names_to = "Date", values_to = "LST") I've decided to add some weather data which might be relevant, inputting this as an additional 7 rows of data in the wide format (see example below of the first 5 months of data). I have belatedly realised that I cannot work out how to pivot this into the long format I need - the documentation doesn't provide enough syntax examples for me to work it out (I've not long been using 'R'). How do I mutate this to provide the additional columns in the long table for the weather variables? Thanks for your time, Philip Part-time PhD Student (Environmental Science) Lancaster University, UK. Wide data -- Buffer15/01/2010 16/02/2010 20/03/2010 24/04/2011 07/05/2010 1006.091741043 6.405879111 8.925945159 6.278147269 6.133940129 2005.271975614 5.994054977 7.375445078 5.805619599 5.537759202 3004.451891901 5.61142085 6.120095292 5.149985946 5.353001442 4003.385694303 4.77953426 5.608927408 4.542354226 4.824773827 5002.900508112 4.305900444 5.61367474 4.320657374 4.520022189 6003.110238149 3.616699448 4.83992 4.006103489 4.188421662 700 3.150580922 2.848148846 4.216782177 3.642003696 3.725611032 800 3.079728958 2.016807672 4.05288041 3.315992643 3.278124347 900 2.327902499 1.452876728 3.779922823 3.181741995 3.29577819 1000 1.641887823 2.120099832 4.267840277 3.321634055 3.551965361 1100 1.63370882 1.661317381 3.747342619 2.814670223 2.807355369 1200 0.986559368 1.133219897 2.414025636 2.180686348 2.166547946 1300 0.920601397 1.237239562 2.647100163 2.253223258 2.411947081 1400 0.571882394 0.93675648 2.272566024 2.07198929 1.954723088 1500 0.340505009 0.7379146 2.526476424 1.912840489 2.003872651 1600 0.813480877 1.026085605 2.643863876 1.825988411 2.278799668 1700 0.47192 0.566766122 1.290173713 1.360936689 1.45967449 1800 0.269067515 0.13349775 0.612263766 0.666152106 0.680354177 1900 0.303179244 0.082892149 0.465457136 0.537232782 0.287185161 Temperautre 1215 16 23 21.5 Wind speed 109 10.5 9.5 9.5 Wind trend 1 1 1 0 1 Wind direction 22.545 67.5 191.2556.25 Humidity 40 44.5 22 24.57 Pressure 1024 1018.5 1025 1005.51015.5 Pressure trend 1 11 1 1 long data - Buffer Date LST Temperature Wind speed .. 1 01.01.21 4 510 2 01.02.21 5 211 3 01.03.21 7 515 4 01.04.21 9 67 5 01.05.21 7 510 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.