Question: (Closed) Merging data coloum wise in R
0
gravatar for David_emir
8 months ago by
David_emir300
India
David_emir300 wrote:

Hello All,

I am using R to merge two different CSV file into one new file. both of them has got gene name (1st column) same and the subsequent columns will be my sample ID, I need the output file as follow'

1st_file.csv

Gene    sample1 sample2 smpleN
a   1   4   7
b   2   5   8
c   3   6   9

2nd_file.csv

Gene    sample3 sample4 smpleN1
a   1   4   7
b   2   5   8
c   3   6   9

I need to have a combined file a

Gene    sample1 sample2 smpleN  sample3 sample4 smpleN1
a   1   4   7   1   4   7
b   2   5   8   2   5   8
c   3   6   9   3   6   9

Please let me know how to get this in R

csv R • 473 views
ADD COMMENTlink modified 7 weeks ago by ewre210 • written 8 months ago by David_emir300
3

What have you tried? You can generally google for things like this.

ADD REPLYlink written 8 months ago by Devon Ryan84k

Run ?cbind and look at the examples.

ADD REPLYlink written 8 months ago by Alex Reynolds25k

Hello David_emir!

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

This is a pure R question. Please search StackOverflow.

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!

ADD REPLYlink written 7 weeks ago by Ram17k
3
gravatar for biplab
8 months ago by
biplab60
University of California, Davis
biplab60 wrote:

Read both files in R. Then use: merge(file1, file2, by='Gene', all=TRUE)

ADD COMMENTlink written 8 months ago by biplab60
0
gravatar for pfs
8 months ago by
pfs250
USA/Boston
pfs250 wrote:

Look into the merge command.

ADD COMMENTlink written 8 months ago by pfs250
0
gravatar for ewre
7 weeks ago by
ewre210
United States
ewre210 wrote:

inner_join from dplyr package is another option if you want:

library(dplyr);library(readr)
d1 = read_csv("1st_file.csv"); d2=read_csv("2st_file.csv")
d3 = inner_join(d1,d2, by = 'Gene')
ADD COMMENTlink written 7 weeks ago by ewre210
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1086 users visited in the last hour