Dear all,
i have tried all of your proposals, all of them was ok.
Maybe dcast() with data table was faster.
Thank you!
Best regards
Gabor
Am Fr., 14. Okt. 2022 um 01:31 Uhr schrieb Dénes Tóth <
toth.de...@kogentum.hu>:
> Or if your data is really large, you can try data.table::dcast().
>
> > l
Or if your data is really large, you can try data.table::dcast().
> library(data.table)
> dcast(ID ~ station, data = as.data.table(df1))
ID xy xz
1: 12 15 20
2: 13 16 19
(Note: instead of `as.data.table()`, you can use `setDT` or create your
object as a data.table in the first place.)
On
Hello,
To reshape from long to wide format, here are two options:
df1 <- 'IDstation value
12 xy15
12 xz20
13 xy 16
13 xz 19'
df1 <- read.table(textConnection(df1), header = TRUE)
# base R
reshape(df1, direction = "wide", idvar = "ID", tim
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,
Dears,
i need to create from a column of observations variables in a datafram like
this way:
example:
original:
IDstation value
12 xy15
12 xz20
13 xy 16
13 xz 19
new df:
ID xy xz
12 15 20
13 16 19
i have been loo
5 matches
Mail list logo