How to read a txt file line by line in R/Rstudio?

前端 未结 3 1785
鱼传尺愫
鱼传尺愫 2021-01-21 04:26

Suppose I have a messy text file like the following for example

Today is a good
day, but I feel very tired. It seems like it is
going to rain pretty soon.
         


        
3条回答
  •  花落未央
    2021-01-21 04:34

    char_vector <- readLines(filename)
    
     txt <- "Today is a good
     day, but I feel very tired. It seems like it is
     going to rain pretty soon."
    
     readLines(textConnection(txt) )
    #   ---- teh screen output of three distinct character elements
    [1] "Today is a good"                                
    [2] "day, but I feel very tired. It seems like it is"
    [3] "going to rain pretty soon."                    
    
    char_vector <- readLines(textConnection(txt))
    
    char_vector[1]
    #[1] "Today is a good"
    

提交回复
热议问题