-2

Cbind bind's the integer number rather content.But while using paste function i could see the content of the text.I'm not sure why it's binding the integer rather the content of the column.

It's not working:

data<-read.csv("NFL.CSV",head=T)
output <- cbind( data$content,  cl$cluster)

Now I could see the content

output <- paste( data$content,  cl$cluster)

Sample Data:There two columns one is content and another one is id

content ,id

NFL flexes Dallas Cowboys-Washington Redskins game  ,  cbbbcf9395705611c3eeeffaa610a602
@special_event32 redskins still suck    ,9b50b8be10460eab6c0f6f3590067bd7
RG3 leads Redskins over Eagles 27-20 (The Associated Press) PHILADELPHIA (AP) -- With one   ,77e1a37031884642b8d1bccad99516c6
samy
  • 65
  • 1
  • 8
  • 1
    Can you add some example data. Otherwise it will be really hard to help you. – Buggy May 04 '16 at 06:20
  • 1
    Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 May 04 '16 at 06:23
  • 1
    It is because you have `factor` columns. Use `stringsAsFactors=FALSE` while reading with `read.csv` or convert to `character` class. – akrun May 04 '16 at 06:29

1 Answers1

3

Since you didn't give any example data, I have to guess, but I strongly suspect that your columns content and/or cluster are factor columns in which case cbind will convert them to integer values:

> cbind(as.factor(c("a", "b")), as.factor(c("a", "c")))
     [,1] [,2]
[1,]    1    1
[2,]    2    2

What you can do is put as.character around your vectors:

> cbind(as.character(as.factor(c("a", "b"))), 
+   as.character(as.factor(c("a", "b"))))
     [,1] [,2]
[1,] "a"  "a" 
[2,] "b"  "b"

or in your example:

output <- cbind(as.character(data$content),
  as.character(cl$cluster))

Another solution is to use cbind.data.frame

> cbind.data.frame(as.factor(c("a", "b")), as.factor(c("a", "b")))
  as.factor(c("a", "b")) as.factor(c("a", "b"))
1                      a                      a
2                      b                      b

or just data.frame

output <- data.frame(content = data$content, 
   cluster = cl$cluster)
Jan van der Laan
  • 8,005
  • 1
  • 20
  • 35