# How to reshape a dataset in R

#1

Hi all,

i am new to R so please help me solving below query.

Query:i need create a data frame of 3 vectors with random values in it and convert 3 vectors to 1 vector without using Reshape package.

To make it simple i need to convert 3 columns to 1 column without Reshape package.

Can that be done.

#2

Hi @sivateja,

just curious, why is it necessary to not use Reshape package?

#3

Hi @jalFaizy,

No specific reason but this is an assignment given to me

#4

Well although I don’t know R, a simple thing you can do is to consider each vector as a string value and concatenate them.

For example,

``````A, B, C
0.1, 0.2, 0.1
0.3, 0.1, 0.2
``````

Concatenating these up with the formula “`str(A) + "-" + str(B) + "-" + str(C )`” will result in the following

``````D
"0.1-0.2-0.1"
"0.3-0.1-0.2"``````

#5

Thank you, will try this.

#6

@sivateja
Hi Siva,
Please use the below mentioned function to get the required output without using reshape

### Creating a data set

a <- c(1,2,3)
b <- c(4,5,6)
d <- c(7,8,9)

e <- as.data.frame(cbind(a,b,d))

#####Function to get the desired output ########
datalist = list()
for (i in 1:nrow(e)) {
f <- paste(e\$a[i], “,”, e\$b[i],",",e\$d[i])
datalist[[i]] <- f
}

h <- do.call(rbind, datalist)