[R] Read

Ista Zahn i@t@z@hn @ending from gm@il@com
Sat Nov 10 13:33:39 CET 2018


readr::read_csv produces the desired result by default:

readr::read_csv("x1,x2,x3,x4,x5
12,13,,14,,
22,23,24,25,26
,33,34,34,")

Best,
Ista
On Fri, Nov 9, 2018 at 8:40 PM Val <valkremk using gmail.com> wrote:
>
> HI all,
> I am trying to read a csv file, but  have a problem in the row names.
> After reading, the name of the first column is now "row.names" and
> all other column names are shifted to the right. The value of the last
> column become all NAs( as an extra column).
>
> My sample data looks like as follow,
> filename = dat.csv
> The first row has a missing value at column 3 and 5. The last row has
> a missing value at column 1 and  5
> x1,x2,x3,x4,x5
> 12,13,,14,,
> 22,23,24,25,26
> ,33,34,34,
> To read the file I used this
>
> dsh<-read.csv(file="dat.csv",sep=",",row.names=NULL,fill=TRUE,header=TRUE,comment.char
> = "", quote = "", stringsAsFactors = FALSE)
>
> The output  from the above  is
> dsh
>
>  row.names x1 x2 x3 x4 x5
> 1        12 13 NA 14 NA  NA
> 2        22 23 24 25 26  NA
> 3             33 34 34 NA  NA
>
> The name of teh frist column is row,banes and all values of last columns is NAs
>
>
> However, the desired output should be
>  x1 x2 x3 x4 x5
>  12 13 NA 14 NA
>  22 23 24 25 26
>  NA 33 34 34 NA
>
>
> How can I fix this?
> Thank you in advance
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list