This is a test version of Biostars. For the public version, visit https://www.biostars.org.
trying to put values of two dimensionless files side by side

I have two text files for which the command dim(file.txt) returns NULL. One of the files contains lines of X coordinates (x1.1, x1.2, x1.3) followed by a second line of coordinates for a separate entities (x2.1, x2.2, x2.3) the other contains corresponding Y coordinates and I'm trying to transform the files into separate the files to create a new file for each line such that the X and Y coordinates will line up side by side like so:

X1 Y1             AND      X2 from line 2, Y2 from line 2
x1.1 y1.1                      x2.1                 y2.1
x1.2 y1.2                      x2.2                 y2.2

etc.

Any tips?

r assembly

Hello chrisclarkson100!

We believe that this post does not fit the main topic of this site.

Not connected to bioinformatics.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

1 answer

It will be better if you can give a sample data next time and what you have tried. Anyway, below is my attempt to answer your question

rm(list=ls())
data1_ID <- c("x1.1","x2.1","x1.2","x2.2","x1.3","x2.3")
data1 <- data.frame( ID= data1_ID,value = c(1:6))
data2_ID <- c("y1.1","y2.1","y1.2","y2.2","y1.3","y2.3")
data2 <- data.frame( ID= data2_ID,value = c(-1:-6))

data1

    ID value
1 x1.1     1
2 x2.1     2
3 x1.2     3
4 x2.2     4
5 x1.3     5
6 x2.3     6

data2

    ID value
1 y1.1    -1
2 y2.1    -2
3 y1.2    -3
4 y2.2    -4
5 y1.3    -5
6 y2.3    -6

odd_row  <- seq(1, nrow(data1), by = 2)
eve_row <- seq(2, nrow(data1), by = 2)
cbind(
+ cbind(data1[odd_row,], data2[odd_row,]),
+ cbind(data1[eve_row,], data2[eve_row,])
+ )

    ID value   ID value   ID value   ID value
1 x1.1     1 y1.1    -1 x2.1     2 y2.1    -2
3 x1.2     3 y1.2    -3 x2.2     4 y2.2    -4
5 x1.3     5 y1.3    -5 x2.3     6 y2.3    -6

Log in to answer this question.