I can understand, this may have been answered earlier in some form, but I didn't have any luck with the solutions. Would be great if you could help me with this.
I have two txt files and I want to merge them. The format of the file is as below:
ID|C1|C2|C3
ID1|a|b|c
ID2|d|e|f
Basically, the respective columns in both txt files are separated by "|"
When I am merging the two files using merge, the error message displayed is 'by' must specify a uniquely valid column.
Also please see below the code.
mydata_1 <- read.delim("file_1.txt", skipNul = TRUE, sep = "|", header = FALSE, row.names = NULL)
mydata_2 <- read.delim("file_2.txt", skipNul = TRUE, sep = "|", header = FALSE, row.names = NULL)
merge(x=mydata_1, y=mydata_2, by = "ID", all = TRUE)
Edit - sharing a few lines of actual data for easy reference.
File 1
MS|T1|T2|T3|T4|T5|T6|T7|T8|T9|T10|T11|T12|T13|T14|T15|T16|T17|T18|T19|T20|T21
1|646.25|129.966666666666666666666666666666666667|67.1|19.3|0|281.5|0|227.25|126|0|0|7.5|0|0|10.5|3|0|6|600|NO|2G
2|573.24|91.2666666666666666666666666666666666667|23.0833333333333333333333333333333333333|3.3|3.703466796875|205|0|84.75|36|37.49|210|0|0|0|0|0|0|14|640|YES|3G
3|955.63|1163.93333333333333333333333333333333333|2.11666666666666666666666666666666666667|5.58333333333333333333333333333333333333|0|248|600|8.25|91.88|0|0|7.5|0|0|0|3|0|21|1050|NO|2G
4|906|306.666666666666666666666666666666666667|24.75|7.35|0|663.5|0|123|63|0|0|2.5|0|0|0|1|0|21|1050|NO|2G
5|147.6|29.4833333333333333333333333333333333333|21.45|0|0|75.6|0|63|0|0|0|9|0|0|0|3.6|0|3|150|NO|2G
File 2
MS|T1|T2|T3|T4|T5|T6|T7|T8|T9|T10|T11|T12|T13|T14|T15|T16|T17|T18|T19|T20|T21
1|100346.25|129.966666666666666666666666666666666667|167.1|19.3|0|281.5|0|227.25|126|0|0|7.5|0|0|10.5|3|0|6|600|NO|2G
2|73.24|91.2666666666666666666666666666666666667|203.0833333333333333333333333333333333333|3.3|3.703466796875|205|0|84.75|36|37.49|210|0|0|0|0|0|0|14|640|YES|3G
3|955.63|1163.93333333333333333333333333333333333|2.11666666666666666666666666666666666667|5.58333333333333333333333333333333333333|0|248|600|8.25|91.88|0|0|7.5|0|0|0|3|0|21|1050|NO|2G
4|906|306.666666666666666666666666666666666667|24.75|7.35|0|663.5|0|123|63|0|0|2.5|0|0|0|1|0|21|1050|NO|2G