简体   繁体   中英

Two columns from a single column values in r

I have data of single column and want to convert into two columns:

beta
   2
.002
  52
 .06
  61
0.09
  70
0.12
  85
0.92

I want into two col as:

col1 col2
2    0.002
52   0.06
61   0.09
70   0.12
85   0.92

Can anyone please help me sort this out????

We can unlist the dataframe and convert it into the matrix of nrow/2 rows

data.frame(matrix(unlist(df), nrow = nrow(df)/2, byrow = T))

#   X1    X2
#1  2 0.002
#2 52 0.060
#3 61 0.090
#4 70 0.120
#5 85 0.920

We can do a logical index and create two columns

i1 <- c(TRUE, FALSE)
df2 <- data.frame(col1 = df1$beta[i1], col2 = df1$beta[!i1])

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