fork download
  1. library(stringr)
  2.  
  3. x <- "There is a horror movie running in the iNox theater. : If row names are supplied of length one and the data
  4. frame has a single row, the row.names is taken to specify the row names and not a column (by name or number).
  5. If row names are supplied of length one and the data frame has a single row, the row.names is taken to specify
  6. the row names and not a column (by name or number) Can we go : Please"
  7.  
  8.  
  9. y <- "There is a horror movie running in the iNox theater. If row names are supplied of length one and the data
  10. frame has a single row, the row.names is taken. To specify the row names and not a column. By name or number. :
  11. If row names are supplied of length one and the data frame has a single row, the row.names is taken to specify
  12. the row names and not a column (by name or number) Can we go : Please"
  13.  
  14. z <- "There is a horror movie running in the iNox theater. If row names are supplied of length one and the data frame has a single row, the row.names is taken to specify the row names and not a column (by name or number).
  15. If row names are supplied of length one. : And the data frame has a single row, the row.names is taken to specify
  16. the row names and not a column (by name or number) Can we go : Please"
  17.  
  18.  
  19. df <- data.frame(Text = c(x, y, z), row.names = NULL, stringsAsFactors = F)
  20.  
  21. resDF <- data.frame("Col1" = character(), "Col2" = character(), stringsAsFactors=FALSE)
  22.  
  23. processData <- function(a) {
  24. patt <- "^(?s)(?!(?:(?:[^:]*?\\.){3,}))(.*?):(.*)$"
  25. if(grepl(patt,a,perl=TRUE))
  26. {
  27. result<-str_match(a,patt)
  28. col1<-result[2]
  29. col2<-result[3]
  30. }
  31. else
  32. {
  33. col1<-"NA"
  34. col2<-a
  35. }
  36. return(c(col1,col2))
  37.  
  38. }
  39.  
  40.  
  41.  
  42. for (i in 1:nrow(df)){
  43. tmp <- df[i, ]
  44. resDF[nrow(resDF) + 1, ] <- processData(tmp)
  45. }
  46.  
  47.  
  48. print(resDF)
  49.  
  50.  
Success #stdin #stdout 0.19s 182464KB
stdin
Standard input is empty
stdout
                                                   Col1
1 There is a horror movie running in the iNox theater. 
2                                                    NA
3                                                    NA
                                                                                                                                                                                                                                                                                                                                                                                                                              Col2
1                                                        If row names are supplied of length one and the data \n    frame has a single row, the row.names is taken to specify the row names and not a column (by name or number). \n    If row names are supplied of length one and the data frame has a single row, the row.names is taken to specify \n    the row names and not a column (by name or number) Can we go : Please
2 There is a horror movie running in the iNox theater. If row names are supplied of length one and the data \n    frame has a single row, the row.names is taken. To specify the row names and not a column. By name or number. : \n    If row names are supplied of length one and the data frame has a single row, the row.names is taken to specify \n    the row names and not a column (by name or number) Can we go : Please
3      There is a horror movie running in the iNox theater. If row names are supplied of length one and the data frame has a single row, the row.names is taken to specify the row names and not a column (by name or number). \n    If row names are supplied of length one. : And the data frame has a single row, the row.names is taken to specify \n    the row names and not a column (by name or number) Can we go : Please