Dear R users; I am trying to read an excel CSV file (1.csv). When I read it as csv file in R, the R shows me the exact number of row. But it puts all columns in one column, while I have 3 or 4 columns in the data frame. " d4 = read.table("./4.csv",sep=";",header=TRUE) Warning messages: 1: In read.table("./4.csv", sep = ";", header = TRUE) : line 1 appears to contain embedded nulls 2: In read.table("./4.csv", sep = ";", header = TRUE) : line 2 appears to contain embedded nulls 3: In read.table("./4.csv", sep = ";", header = TRUE) : line 3 appears to contain embedded nulls 4: In read.table("./4.csv", sep = ";", header = TRUE) : line 4 appears to contain embedded nulls 5: In read.table("./4.csv", sep = ";", header = TRUE) : line 5 appears to contain embedded nulls 6: In read.table("./4.csv", sep = ";", header = TRUE) : line 1 appears to contain embedded nulls 7: In scan(file = file, what = what, sep = sep, quote = quote, dec dec, : embedded nul(s) found in input> attach(d4) > dim(d4)[1] 1814394 1 " I opened the csv file in excel and I tried to make a new csv (delimited) file. I dont know why in the "save as type" box Unicode text (*.txt) is written. Why the format is txt while the file extension is .CSV? Please help me to read this format correctly. Many thanks. -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat194 at yahoo.com [[alternative HTML version deleted]]
Hi Javad, Unicode characters do have embedded nulls. Try this: d4<-read.table("./4.csv",sep=";",header=TRUE,encoding="UTF-8") Jim On Tue, Jul 2, 2019 at 3:47 AM javad bayat <j.bayat194 at gmail.com> wrote:> > Dear R users; > I am trying to read an excel CSV file (1.csv). When I read it as csv file > in R, the R shows me the exact number of row. But it puts all columns in > one column, while I have 3 or 4 columns in the data frame. > " > d4 = read.table("./4.csv",sep=";",header=TRUE) > Warning messages: > 1: In read.table("./4.csv", sep = ";", header = TRUE) : > line 1 appears to contain embedded nulls > 2: In read.table("./4.csv", sep = ";", header = TRUE) : > line 2 appears to contain embedded nulls > 3: In read.table("./4.csv", sep = ";", header = TRUE) : > line 3 appears to contain embedded nulls > 4: In read.table("./4.csv", sep = ";", header = TRUE) : > line 4 appears to contain embedded nulls > 5: In read.table("./4.csv", sep = ";", header = TRUE) : > line 5 appears to contain embedded nulls > 6: In read.table("./4.csv", sep = ";", header = TRUE) : > line 1 appears to contain embedded nulls > 7: In scan(file = file, what = what, sep = sep, quote = quote, dec > dec, : > embedded nul(s) found in input > > attach(d4) > > dim(d4) > [1] 1814394 1 > " > I opened the csv file in excel and I tried to make a new csv (delimited) > file. I dont know why in the "save as type" box Unicode text (*.txt) is > written. Why the format is txt while the file extension is .CSV? > Please help me to read this format correctly. > Many thanks. > > > > -- > Best Regards > Javad Bayat > M.Sc. Environment Engineering > Alternative Mail: bayat194 at yahoo.com > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
Should that encoding="UTF-8" be encoding="UTF-16"? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jul 1, 2019 at 2:45 PM Jim Lemon <drjimlemon at gmail.com> wrote:> Hi Javad, > Unicode characters do have embedded nulls. Try this: > > d4<-read.table("./4.csv",sep=";",header=TRUE,encoding="UTF-8") > > Jim > > On Tue, Jul 2, 2019 at 3:47 AM javad bayat <j.bayat194 at gmail.com> wrote: > > > > Dear R users; > > I am trying to read an excel CSV file (1.csv). When I read it as csv file > > in R, the R shows me the exact number of row. But it puts all columns in > > one column, while I have 3 or 4 columns in the data frame. > > " > > d4 = read.table("./4.csv",sep=";",header=TRUE) > > Warning messages: > > 1: In read.table("./4.csv", sep = ";", header = TRUE) : > > line 1 appears to contain embedded nulls > > 2: In read.table("./4.csv", sep = ";", header = TRUE) : > > line 2 appears to contain embedded nulls > > 3: In read.table("./4.csv", sep = ";", header = TRUE) : > > line 3 appears to contain embedded nulls > > 4: In read.table("./4.csv", sep = ";", header = TRUE) : > > line 4 appears to contain embedded nulls > > 5: In read.table("./4.csv", sep = ";", header = TRUE) : > > line 5 appears to contain embedded nulls > > 6: In read.table("./4.csv", sep = ";", header = TRUE) : > > line 1 appears to contain embedded nulls > > 7: In scan(file = file, what = what, sep = sep, quote = quote, dec > > dec, : > > embedded nul(s) found in input > > > attach(d4) > > > dim(d4) > > [1] 1814394 1 > > " > > I opened the csv file in excel and I tried to make a new csv (delimited) > > file. I dont know why in the "save as type" box Unicode text (*.txt) is > > written. Why the format is txt while the file extension is .CSV? > > Please help me to read this format correctly. > > Many thanks. > > > > > > > > -- > > Best Regards > > Javad Bayat > > M.Sc. Environment Engineering > > Alternative Mail: bayat194 at yahoo.com > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at 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. > > ______________________________________________ > R-help at 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. >[[alternative HTML version deleted]]
> I am trying to read an excel CSV file (1.csv). When I read it as csv file > in R, the R shows me the exact number of row. But it puts all columns in > one column, while I have 3 or 4 columns in the data frame. > d4 = read.table("./4.csv",sep=";",header=TRUE)Firstly, I recommend against naming your file "1.csv". (Start with a letter not a number). Secondly, a CSV file should be separated by commas not semicolons. You can specify sep=",", however, it's probably easier to use the read.csv() function. Note that you should be able to open your file in a text editor to see the separators.> I dont know why in the "save as type" box Unicode text (*.txt)Other posters have suggested that you need to specify the encoding. Assuming that you create your CSV file correctly in Excel, I doubt that this is necessary, but I could be wrong... Your comment suggests that you have saved your document as "Unicode text". You need to tell Excel to save the file as a CSV file. (There should be a list of save options). Simply typing a file name with a .csv file extension is unlikely to produce the desired result. [[alternative HTML version deleted]]
Don't be so US-centric, Abby... how do you know that javad's version of Excel doesn't default to using semicolons? ?read.csv2 On July 1, 2019 6:06:32 PM PDT, Abby Spurdle <spurdle.a at gmail.com> wrote:>> I am trying to read an excel CSV file (1.csv). When I read it as csv >file >> in R, the R shows me the exact number of row. But it puts all columns >in >> one column, while I have 3 or 4 columns in the data frame. >> d4 = read.table("./4.csv",sep=";",header=TRUE) > >Firstly, I recommend against naming your file "1.csv". >(Start with a letter not a number). > >Secondly, a CSV file should be separated by commas not semicolons. >You can specify sep=",", however, it's probably easier to use the >read.csv() function. > >Note that you should be able to open your file in a text editor to see >the >separators. > >> I dont know why in the "save as type" box Unicode text (*.txt) > >Other posters have suggested that you need to specify the encoding. >Assuming that you create your CSV file correctly in Excel, I doubt that >this is necessary, but I could be wrong... > >Your comment suggests that you have saved your document as "Unicode >text". >You need to tell Excel to save the file as a CSV file. >(There should be a list of save options). > >Simply typing a file name with a .csv file extension is unlikely to >produce >the desired result. > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at 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.-- Sent from my phone. Please excuse my brevity.