Categories
Uncategorized

Number of Entries – R

The problem is that I have a large list of actors, and I need to count the number of times they have been involved in a conversation.

So each time an actor participates in a conversation, their name gets written down. So I have a really long list, with a few names, that repeat several times.

All I need to do is count them.

First, import their names into R

tUL<-read.table("location")

then convert that into a data frame

dfUL<-as.data.frame(tUL)

Then get the names and the number of times they repeat

repUL<-table(dfUL)

But the output will still be all over the place, so the best way to order them is to create a matrix with them

mUL<-as.matrix(table(dfUL))

Now we can write it to a CSV file so we can open it and arrange some stuff around.

write.table(mUL,"location",sep=",",quote=FALSE,col.names=FALSE)

This makes sure we have the “,” as the separators, no quotes, and no column names.
That’s all.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s