Question: R - removing column names from matrix
1
gravatar for F
3.3 years ago by
F3.4k
Iran
F3.4k wrote:

hi, 

i have a correlation matrix of genes but i am going to remove alphabet from rows and columns to prepare my file for matlb i did like below

> mycounts <- read.table("tmatnorm_rld500.txt", header = T, sep = "\t", row.names=1)
> head(mycounts[,1:3])
          AT1G01060 AT1G01170 AT1G01180
AT1G01060 1.0000000 0.3193360 0.6272994
AT1G01170 0.3193360 1.0000000 0.3178880
AT1G01180 0.6272994 0.3178880 1.0000000
AT1G01260 0.2658624 0.3588030 0.2542234
AT1G01380 0.6178751 0.1561297 0.7052692
AT1G01490 0.5990499 0.6129301 0.6424225
> rownames(mycounts) <- NULL
> head(mycounts[,1:3])
     AT1G01060 AT1G01170 AT1G01180
[1,] 1.0000000 0.3193360 0.6272994
[2,] 0.3193360 1.0000000 0.3178880
[3,] 0.6272994 0.3178880 1.0000000
[4,] 0.2658624 0.3588030 0.2542234
[5,] 0.6178751 0.1561297 0.7052692
[6,] 0.5990499 0.6129301 0.6424225
> colnames(mycounts) <- NULL
>
> head(mycounts[,1:3])
          [,1]      [,2]      [,3]
[1,] 1.0000000 0.3193360 0.6272994
[2,] 0.3193360 1.0000000 0.3178880
[3,] 0.6272994 0.3178880 1.0000000
[4,] 0.2658624 0.3588030 0.2542234
[5,] 0.6178751 0.1561297 0.7052692
[6,] 0.5990499 0.6129301 0.6424225

> write.table(mycounts, file = "correlation.txt", dec = ".", sep = "\t", quote = FALSE, row.names=F)
> mycounts <- read.table("correlation.txt", header = T, sep = "\t")
> head(mycounts[,1:3])
         V1        V2        V3 <---this line
1 1.0000000 0.3193360 0.6272994
2 0.3193360 1.0000000 0.3178880
3 0.6272994 0.3178880 1.0000000
4 0.2658624 0.3588030 0.2542234
5 0.6178751 0.1561297 0.7052692
6 0.5990499 0.6129301 0.6424225

but as you consider, i have something in colnames?? then how I can get rid of alphabet and only have the similarity values please?

thank you

R • 6.3k views
ADD COMMENTlink modified 6 days ago by RamRS21k • written 3.3 years ago by F3.4k
5
gravatar for Sean Davis
3.3 years ago by
Sean Davis25k
National Institutes of Health, Bethesda, MD
Sean Davis25k wrote:

Add col.names=FALSE to the write.table() command and you should have a matrix with no row or column names.

ADD COMMENTlink modified 6 days ago by RamRS21k • written 3.3 years ago by Sean Davis25k
4
gravatar for F
3.2 years ago by
F3.4k
Iran
F3.4k wrote:
write.table(m,file="outfile,txt",sep="\t", col.names = F, row.names = F)
ADD COMMENTlink modified 6 days ago by RamRS21k • written 3.2 years ago by F3.4k
4
gravatar for Benn
3.3 years ago by
Benn6.6k
Netherlands
Benn6.6k wrote:

V1 to V3 is what R assigns to columns, when there are no header names!

Try open your text file in notepad or something similar and see if you have colnames in there?

ADD COMMENTlink modified 6 days ago by RamRS21k • written 3.3 years ago by Benn6.6k
1

thank you my file was too big to be opened in notepad ++ 

ADD REPLYlink written 3.3 years ago by F3.4k
2

You could use less, vi, or head -1 tmatnorm_rld500.txt to see the first line(s) of your file without having to open it.

ADD REPLYlink modified 6 days ago by RamRS21k • written 3.3 years ago by alesssia510
1

sorry you mean I did like below

> less(mycounts)
Error: could not find function "less"
> head -1 mycounts
Error: unexpected symbol in "head -1 mycounts"
ADD REPLYlink modified 6 days ago by RamRS21k • written 3.3 years ago by F3.4k
3

less, vi, and head are all linux/unix commands that will not run in R.

ADD REPLYlink modified 6 days ago by RamRS21k • written 3.3 years ago by Sean Davis25k
2

These (less, head, vi) are bash commands working only in pure linux. These commands do not work in R unless you invoke the system or system2 function in R

ADD REPLYlink modified 6 days ago by RamRS21k • written 3.2 years ago by Antonio R. Franco4.0k
1

I am in windows

ADD REPLYlink written 3.2 years ago by F3.4k
2

Try to use notepad++ directly (easier for you) or the col-names and row-names FALSE

ADD REPLYlink modified 6 days ago by RamRS21k • written 3.2 years ago by Antonio R. Franco4.0k
1

thank you Antonio

ADD REPLYlink written 3.2 years ago by F3.4k
2

I am not an ms-dos expert, but you can check your file in the command line console of windows. If you open the program Command Prompt, you'll have to go to your directory with your file and type in:

more file.txt

It will show you the first 'page' of your file, you can then stop showing it with CTRL-break.

ADD REPLYlink modified 6 days ago by RamRS21k • written 3.2 years ago by Benn6.6k
1

thank you for your suggestion

ADD REPLYlink written 3.2 years ago by F3.4k
2
gravatar for Antonio R. Franco
3.3 years ago by
Spain. Universidad de Córdoba
Antonio R. Franco4.0k wrote:

Or use the notepad++ program as I showed you to erase and edit the file

ADD COMMENTlink modified 6 days ago by RamRS21k • written 3.3 years ago by Antonio R. Franco4.0k
Please log in to add an answer.

Help
Access

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