0

I have 3 factor sets with 5 sentences in it. Now I want to have 1 list with all 15 sentences underneath each other. I guess the problem is I do not know for what function I am searching.

dataset1_sample <- sample(dataset1$twt_txt, 5)
dataset2_sample <- sample(dataset2$twt_txt, 5)
dataset3_sample <- sample(dataset3$twt_txt, 5)

dataset1_sample
[1] These                                                    
[2] Are                                                                      
[3] My                                  
[4] Test   
[5] Words                       
9741 Levels: ''A lot of text'' That I do not understand why it is all in here. 

class(dataset1_sample) = factor

Now I want a list of these three samples. I tried

listoflists <- list(list(dataset1_sample),list(dataset2_sample))

Which is partially correct because it does add them under one name. It just does not put them underneath each other.

test <- cbind(dataset1_sample, dataset2_sample)

This gives me the number of the locations of the sentences in the original dataset. I guess I can use them to select them again in a new list but I assume there should be an easier way.

Zuenie
  • 963
  • 2
  • 11
  • 30
  • Could you please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Do you really want to have `factors`? – sgibb Apr 13 '14 at 10:33
  • I was trying to. The problem is that the original dataset is quite large and I do not know how to create a small sample set with levels in there. And no I guess I do not want factors. – Zuenie Apr 13 '14 at 10:35
  • 1
    Try to use `stringsAsFactors=FALSE` in your import function (`read.table`, `read.csv` or what ever). Without an reproducible example it is hard for us to help. – sgibb Apr 13 '14 at 10:43
  • I am using readOGR and I used stringsAsFactors=FALSE, now my samplesets are of class "character". And now I can just use c(dataset1_sample, dataset2_sample, dataset3_sample) to give me the right result. Thank you sgibb! I did not know I had to change the datatype to get to the answer you helped me a lot! Answer it down here and I will give you credit for it, else I cant close the question. – Zuenie Apr 13 '14 at 10:51

1 Answers1

1

You have factors and want to use/treat it as characters. To get rid of the factor (and its corresponding levels) you could set the stringAsFactors argument of most import functions read.csv/read.table, etc. to TRUE, e.g.:

df <- read.csv("file.csv", stringsAsFactors=TRUE)
sgibb
  • 25,396
  • 3
  • 68
  • 74