简体   繁体   中英

Reshape a row to columns based in condition data frame R

I have this data frame in R:

               x
1   simon.jones@studio24.net
2   beth.parkin@mrc-cbu.cam.ac.uk
3   43
4   simon.jones@studio24.net
5   isaac.lowe@studio24.net
6   13
7   simon.jones@studio24.net
8   samp466@gmail.com
9   31
10  simon.jones@studio24.net
11  suli447@googlemail.com
12  32

I would like to have a data frame with 3 columns, not just one:

                x                          y                  value
1   simon.jones@studio24.net  beth.parkin@mrc-cbu.cam.ac.uk    43
.
.
.

How can I reshape my data frame for infinite rows to get the 3 columns?

What about this?

as.data.frame(matrix(unlist(df), ncol=3, byrow = T))
                        V1                            V2 V3
1 simon.jones@studio24.net beth.parkin@mrc-cbu.cam.ac.uk 43
2 simon.jones@studio24.net       isaac.lowe@studio24.net 13
3 simon.jones@studio24.net             samp466@gmail.com 31
4 simon.jones@studio24.net        suli447@googlemail.com 32

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM