Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

read csv in r

#utils Package
##Output as Data Frame
###Mother Import Function of two functions below    
read.table("data.txt", sep = "", col.names = c("x", "y"), 
           colClasses = c("factor", "NULL"))
    
        read.csv("data.csv", stringAsFactor = F, header = F) #Header and SAF Default True
        read.delim("data.txt", stringAsFactor = F, header = F) #Header and SAF Default True
##col.names and colClasses argument could be also passed in read.csv() and read.delim() function

#readr Package
##Output as tbl_df, tbl & data.frame
###Mother Import Function of two functions below    
read_delim("data.txt", col_names = c("x", "y"), col_names
           delim = "" #delim in readr is same as sep in utils 
           col_types = "cd") # c = character, d = double, i = integer, l = logical, _ = skip        
           
        read_csv("data.csv") #SAF Default FALSE, header Default True
        read_tsv("data.txt")
        
#fread function (data.table Package)
##Output as data.table & data.frame 
fread("data.csv", #Default auto determine header, coltypes and sep
      drop = 2:4,
      select = c("a", "e"))
Source by itsmycode.com #
 
PREVIOUS NEXT
Tagged: #read #csv
ADD COMMENT
Topic
Name
9+4 =