sink a data frame to .txt file

后端 未结 2 1946
不思量自难忘°
不思量自难忘° 2021-01-24 21:47

I have a 4-column data frame named as mytable with hundreds of rows. It looks like

id         name                   count        rate
234     uert e@3 erwafrw         


        
2条回答
  •  执笔经年
    2021-01-24 22:11

    seems like write.table() should be OK. just specify a seperator, like ",", or something else not appearing in your name column:

        my.df <- data.frame(ID=c(234,324,329,123), 
          name = c("uert e@3 erwafrw23 weq"," awrt%rw-fref-sfr-32 eq","jiowerfhguy qwhrb","234huib|f|wer fwfqwasgre"),
          count = c(34,78,90,54), rate = c(2,4,8,3))
    
        write.table(my.df, file = "my.df.txt", sep = ",", col.names = colnames(my.df))
    
        # read it back in
        my.df2 <- read.table(file = "my.df.txt",sep = ",", header = TRUE, stringsAsFactors = FALSE) 
    
        all(my.df == my.df2) 
        TRUE
    

提交回复
热议问题