Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove ID from write.table CSV output [duplicate]

Tags:

r

When I execute this statement:

write.table(bigdata, 'news.csv', sep = ',')

It outputs like this:

"type","text"
"1","neutral","The week in 32 photos"
"2","neutral","Look at me! 22 selfies of the week"
"3","neutral","Inside rebel tunnels in Homs"
"4","neutral","Voices from Ukraine"
"5","neutral","Water dries up ahead of World Cup"
"6","positive","Who's your hero? Nominate them"

However, I don't want that ID column, the numbers that appear like 1,2,3,4... I just want this:

"type","text"
"neutral","The week in 32 photos"
"neutral","Look at me! 22 selfies of the week"
"neutral","Inside rebel tunnels in Homs"
"neutral","Voices from Ukraine"
"neutral","Water dries up ahead of World Cup"
"positive","Who's your hero? Nominate them"

Here is my dataframe:

> head(bigdata)
      type                               text
1  neutral              The week in 32 photos
2  neutral Look at me! 22 selfies of the week
3  neutral       Inside rebel tunnels in Homs
4  neutral                Voices from Ukraine
5  neutral  Water dries up ahead of World Cup
6 positive     Who's your hero? Nominate them

How can I remove the ID from the output?

like image 630
user1477388 Avatar asked Jun 13 '14 15:06

user1477388


People also ask

How do I remove a column ID in R?

To remove a character in an R data frame column, we can use gsub function which will replace the character with blank. For example, if we have a data frame called df that contains a character column say x which has a character ID in each value then it can be removed by using the command gsub("ID","",as.

How do you export a CSV file from R?

csv() Use write. csv() to export R DataFrame to CSV file with fields separated by comma delimiter, header (column names), rows index, and values surrounded with double-quotes.


1 Answers

Specifying row.names = FALSE in the write.table() function will remove that id column.

like image 178
ccapizzano Avatar answered Sep 20 '22 23:09

ccapizzano