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?
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.
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.
Specifying row.names = FALSE
in the write.table()
function will remove that id column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With