Displaying 16 results from an estimated 16 matches for "pivot_long".
Did you mean:
pivot_longer
2024 Jun 12
1
my R code worked well when running the first 1000 lines of R code
...h Bert and Tim guessed my problem correctly. I also thought about the conflicting issue between different packages and function masking.
> I just hope to that someone has similar experience, so providing me suggestion.
>
> For conflicting issue,
>
> What I tried was to add dplyr::pivot_longer or tidyr:: pivot_longer,
Do that to all functions comming from contributed packages. At least to
those.
summary_anno1148ft <- anno1148ft %>%
tidyr::pivot_longer(c(t_depth, t_alt_count, t_alt_ratio), names_to =
"measure") %>%
dplyr::group_by(dat, measure) %>%...
2024 Jun 12
1
my R code worked well when running the first 1000 lines of R code
Hi Rui,
Thank you very much!
Yes, I verified using real data, it worked correctly as expected after adding tidyr:: to the pivot_longer function and dplyr:: to the group_by and summarize
Function.
I did not know how to assign the tidyr and dplyr to the three functions because I do not really understand well the three functions and just got the code from a google search.
I also tried your simplified code, but got the following e...
2024 Jun 12
1
my R code worked well when running the first 1000 lines of R code
...so I can not share.
Both Bert and Tim guessed my problem correctly. I also thought about the conflicting issue between different packages and function masking.
I just hope to that someone has similar experience, so providing me suggestion.
For conflicting issue,
What I tried was to add dplyr::pivot_longer or tidyr:: pivot_longer, but still not resolved the problem.
I will restart from the first line my code, it will work again and then I will track down.
Thank you,
Ding
From: CALUM POLWART <polc1410 at gmail.com>
Sent: Wednesday, June 12, 2024 10:52 AM
To: Yuan Chun Ding <ycding...
2024 Jun 12
1
my R code worked well when running the first 1000 lines of R code
...ed.
> However, after running another 2000 lines of R codes using functions from
> more than 10 other R libraries, then it only generated one column of
> summary.
> Do you know why?
>
> Thank you,
>
> Yuan Chun Ding
>
> summary_anno1148ft <- anno1148ft %>%
> pivot_longer(c(t_depth, t_alt_count, t_alt_ratio), names_to = "measure")
> %>%
> group_by(dat, measure) %>%
> summarize(minimum = min(value,na.rm=T),
> q25 = quantile(value, probs = 0.25,na.rm=T),
> med = median(value,na.rm=T),
> q75 =...
2024 Dec 10
1
Heat maps containing two types of variables
...s. Thanks for your help.
Philip
# REPREX
library(ggplot2)
library(tidyr)
library(dplyr)
dat <- data.frame(
date=seq.Date(as.Date("2024-01-01"),as.Date("2024-06-01"),by="month"),
A=c(1,3,3,4,2,6),
B=c(3,5,6,4,8,9),
C=c(10,8,17,19,26,22)
)
dat_long <- pivot_longer(dat,2:4,names_to="variable",values_to="value")
normalize <- function(x) { y <- (x-min(x))/(max(x)-min(x)) }
dat_norm <- mutate(dat,across(2:4,normalize))
dat_long_norm <-
pivot_longer(dat_norm,2:4,names_to="variable",values_to="norm_value")
dat...
2024 Jun 12
3
my R code worked well when running the first 1000 lines of R code
...unt, t_alt_ratio), 12 columns of summary, see attached.
However, after running another 2000 lines of R codes using functions from more than 10 other R libraries, then it only generated one column of summary.
Do you know why?
Thank you,
Yuan Chun Ding
summary_anno1148ft <- anno1148ft %>%
pivot_longer(c(t_depth, t_alt_count, t_alt_ratio), names_to = "measure") %>%
group_by(dat, measure) %>%
summarize(minimum = min(value,na.rm=T),
q25 = quantile(value, probs = 0.25,na.rm=T),
med = median(value,na.rm=T),
q75 = quantile(value, probs = 0.75,n...
2023 Apr 04
1
Simple Stacking of Two Columns
Just to repeat:
you have
NamesWide<-data.frame(Name1=c("Tom","Dick"),Name2=c("Larry","Curly"))
and you want
NamesLong<-data.frame(Names=c("Tom","Dick","Larry","Curly"))
There must be something I am missing, because
NamesLong <- data.frame(Names = c(NamesWide$Name1, NamesWide$Name2))
appears to
2023 May 02
1
Reg: Help regarding ggplot2
...uot;, 1.04, 0.615, 1.69, 2.48, 0.346, 0.509, 0.630, 1.01)
-> data_vol3
### please give us data using dput in future: saves us having to do
something like that to reclaim it!
### pivot that longer to make it easy to get country data as separate lines
data_vol3 %>%? select(-rowN) %>%
? pivot_longer(cols = -index, # as you want to pivot the other
variables/columns
?????????????? names_to = "countries") -> tibDataVol3Long
ggplot(data = tibDataVol3Long,
?????? aes(x = index, y = value,
???????????? ### now get the grouping and use it for a colour legend
???????????? group =...
2023 Oct 31
1
weights vs. offset (negative binomial regression)
...model, as below.
>
> ? ?cheers
> ? ? Ben Bolker
>
>
> edata <- data.frame(Catch, Effort, xx1, xx2, xx3)
>
> ## graphical exploration
>
> library(ggplot2); theme_set(theme_bw())
> library(tidyr)
> edata_long <- edata |> pivot_longer(names_to="var", cols =-c("Catch",
> "Effort"))
> ggplot(edata_long, aes(value, Catch)) +
> ? ? ?geom_point(alpha = 0.2, aes(size = Effort)) +
> ? ? ?facet_wrap(~var, scale="free_x") +
> ? ? ?geom_smooth(method = "g...
2023 Dec 04
2
Transformar una base de datos a matriz
Buenos d?as.
Tengo una duda:
Trabajo con comundiades de especies, y mis datos se ordenan de tal forma que, cada especie corresponde a una fila de la base de datos, por lo que cada muestra tiene un n?mero de filas correspondiente al n?mero de especies. Mi objetivo es transformar esa base de datos a un formato de matriz donde, cada muestra sea una fila ?nica y las especies sean las columnas, con
2024 Jun 28
1
Ayuda para hacer una lista
Hola, que tal?
Sin saber nada mas de los datos, por lo que dices, mi aprioximacion
seria usar la funcion split, e.g.:
splittedData <- split(myData, "variablegrupo/condicion")
Esto te crearia una lista con tantos objectos como condiciones tengas.
Saludos
On 6/27/24 10:15, Leticia G Leon wrote:
> Muchas fracias por la rapida contastacion Javier.
>
> Si, ya me he dado
2023 May 16
0
Newbie: Controlling legends in graphs
...plot code
> library(ggplot2)
> library(dplyr)
> library(tidyr)
> library(lubridate)
>
> weights %>%
> ??? mutate(Year = year(Date)) %>%
> ??? group_by(Year) %>%
> ??? summarize(across(J:K, mean, na.rm = TRUE)) %>%
> ??? # now reshape the data
> ??? pivot_longer(-Year) %>%
> ??? # uncomment the next line if you want K
> ??? # to show up on top in the legend
> ??? # mutate(name = factor(name, levels = c("K", "J"))) %>%
> ??? ggplot(aes(Year, value, color = name)) +
> ??? geom_smooth(
> ??????? formula = y...
2023 Apr 03
1
Simple Stacking of Two Columns
Hi,
You were on the right track using stack(), but you just pass the entire data frame as a single object, not the separate columns:
> stack(NamesWide)
? values ? ind
1 ? ?Tom Name1
2 ? Dick Name1
3 ?Larry Name2
4 ?Curly Name2
Note that stack also returns the index (second column of 'ind' values), which tells you which column in the source data frame the stacked values originated
2023 May 12
2
Newbie: Controlling legends in graphs
Hello, I'm trying to create a line graph with a legend, but have no
success controlling the legend. Since nothing I've tried seems to work,
I must be doing something systematically wrong. Can anyone point this
out to me?
Here's my data:
> weights
# A tibble: 1,246 ? 3
Date J K
<date> <dbl> <dbl>
1 2000-02-13 133 188
2
2023 May 02
5
Reg: Help regarding ggplot2
Dear All,
I have a dataset which contains date and 12 other countries data. I
have extracted the data as xts object.
I am not able to recall all the series in the Y axis. My data set
looks like this
index crepub finland france germany italy netherlands norway poland
<date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
2023 Apr 03
4
Simple Stacking of Two Columns
Hi R-Helpers,
Sorry to bother you, but I have a simple task that I can't figure out how to do.
For example, I have some names in two columns
NamesWide<-data.frame(Name1=c("Tom","Dick"),Name2=c("Larry","Curly"))
and I simply want to get a single column