Reputation: 1
I need help with restructuring my data frame.
I currently have the following data structure: Current data structure
I need to get to this :
post 229 comments 220 badge 209 washington 160
Notice that I do not need the serial numbers or the column names. I only need the word and the frequency posted adjacent to it. Any package will do.
Upvotes: 0
Views: 64
Reputation: 1
thanks for your help but I figured it out. I had to use the command rbind.
Here is my code:
#Bind the matrix together
result <- matrix(rbind(df[,1],ft[,2]))
#Transpose the binded matrix to get desired shape
FreqTerms <- t(result)
Upvotes: 0
Reputation: 3833
Set row.names=FALSE
in print
statement, better to write it out with row.names=FALSE
and col.names=FALSE
into an output file
df <- data.frame(WORD=c("post","comments","badge","washington"),FREQ=c(229,220,209,160))
print (df, row.names=FALSE) # You have to use print
# Creating dataframe without column names
df <- data.frame(c("post","comments","badge","washington"),c(229,220,209,160))
You can directly write it out as below:
write.table(df,file="MyFile.txt",row.names=FALSE,col.names=FALSE,quote=FALSE,sep="\t")
Upvotes: 0