[R] splitting a column of data into multiple columns

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Fri Jun 28 23:45:38 CEST 2019


Hi Janet,
This might help:

jcdf<-read.table(text="scen trans evap flow
1       1.1    0.1    0.09
1       1.2    0.2    0.10
1       1.3    0.3    0.20
2       2.1    0.1    0.09
2       2.2    0.2    0.10
2       2.3    0.3    0.20
3       3.1    0.1    0.09
3       3.2    0.2    0.10
3       3.3    0.3    0.20",
header=TRUE)
library(prettyR)
stretch_df(jcdf,"scen",c("trans","evap","flow"))[,2:10]

Jim


On Sat, Jun 29, 2019 at 1:42 AM Janet Choate <jsc.eco using gmail.com> wrote:
>
> Hello R community,
> I have a data frame that has multiple observations in a single column that
> I would like to break into multiple columns.
> The data looks something like this:
>
> scen trans evap flow
> 1       1.1    0.1    0.09
> 1       1.2    0.2    0.10
> 1       1.3    0.3    0.20
> 2       2.1    0.1    0.09
> 2       2.2    0.2    0.10
> 2       2.3    0.3    0.20
> 3       3.1    0.1    0.09
> 3       3.2    0.2    0.10
> 3       3.3    0.3    0.20
>
> the column scen runs from 1 through 500, and each scen # contains 1461 rows
> - i.e. there are 1461 observations for scen1, 1461 observations for scen2,
> etc...
> i want to split the trans, evap, and flow columns out by scen #, so that i
> end up with something like:
>
> trans1   trans2    trans3
> 1.1         2.1        1.1
> 1.2         2.2        3.2
> 1.3         2.3        3.3
>
> and same for the other variables.
> thought i could use the separate command to do this, but either not the
> right approach or i am not executing it properly.
> thank you for any assistance,
> Janet
> --
> Tague Team Lab Manager
> 1005 Bren Hall
> UCSB, Santa Barbara, CA.
>
>         [[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