[R] intersection in data frame
Ben Tupper
btupper @end|ng |rom b|ge|ow@org
Thu Oct 13 23:17:33 CEST 2022
Hi,
If you are game to use a tidy approach then you can use tidyr::pivot_wider()
library(dplyr)
library(tidyr)
x <- dplyr::tribble(
~ID, ~station, ~value,
12, "xy", 15,
12, "xz", 20,
13, "xy", 16,
13, "xz", 19)
tidyr::pivot_wider(x,
names_from = station,
values_from = value)
#> # A tibble: 2 × 3
#> ID xy xz
#> <dbl> <dbl> <dbl>
#> 1 12 15 20
#> 2 13 16 19
Cheers,
Ben
On Thu, Oct 13, 2022 at 5:07 PM Gábor Malomsoki
<gmalomsoki1980 using gmail.com> wrote:
>
> Dears,
>
> i need to create from a column of observations variables in a datafram like
> this way:
> example:
> original:
> ID station value
> 12 xy 15
> 12 xz 20
> 13 xy 16
> 13 xz 19
>
> new df:
>
> ID xy xz
> 12 15 20
> 13 16 19
>
> i have been looking around for examples, but i could not find any how to
> change my df.
> I would like to make regression analysis on the values from different
> production stations, so my df is very huge.
>
> Please help on finding the package, description or anything else could help.
>
> Thank you in advance!
>
> Best regards
> Malo
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using 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.
More information about the R-help
mailing list