简体   繁体   中英

Obtain a data frame using write.table without initial part of every row in R

I have a data frame in which rows are like this: xyz-1; xyz-2; and so on

data frame x:

      1 2 3
xyz-1 1 4 e
xyz-2 2 5 a
xyz-3 3 6 c

I tried write.table(x,file="out") ; x is my data frame. When i use write.table , i want the text file (output) whose rows are in the form: 1;2;...;

How can i do this? How can i remove the initial part of every row (xyz)?

You can remove the "xyz - " part with: rownames(x) <- NULL .

Alternative: rownames(x) <- gsub("xyz-", "", rownames(x)) This replaces "xyz-" with "" (nothing) so it removes it.

Make sure the pattern is "xyz-" exactly, or if you need a space somewhere (like "xyz -").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM