user2808642
user2808642

Reputation: 95

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????

Upvotes: 0

Views: 74

Answers (2)

akrun
akrun

Reputation: 886948

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])

Upvotes: 1

Ronak Shah
Ronak Shah

Reputation: 388817

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

Upvotes: 1

Related Questions