Christa Rose
2016-Jul-14 22:49 UTC
[R] Please help: cannot import files from Windows into R
Can someone please help? The read.table command is not working for me I think because Windows has my account name stored as "Christa Rose" with a space in it. Is this a problem? I have tried many syntax iterations, and cannot get around this. Here is an example of the syntax I've used:> RanMinePlay<-read.table("c:\\Users\\ChristaRose\\Desktop\\Ran_mine_play_data.txt",header=T) And returned error messages: in read.table("c:\\Users\\Christa Rose\\Desktop\\Ran_mine_play_data.txt", : empty beginning of file In addition: Warning messages: 1: In read.table("c:\\Users\\Christa Rose\\Desktop\\Ran_mine_play_data.txt", : line 1 appears to contain embedded nulls 2: In read.table("c:\\Users\\Christa Rose\\Desktop\\Ran_mine_play_data.txt", : incomplete final line found by readTableHeader on 'c:\Users\Christa Rose\Desktop\Ran_mine_play_data.txt Can someone help me resolve this?? Christa Rose *He is certain too that the cats, of whom there are many in the woods, have a language of their own - some kind of old Irish. From "Enchanted Woods", **William Butler Yeats* *It is in stone that the most abundant testimony is found of craftsmanship in medieval Ireland. From Heritage of Ireland, **Brian de Breffny* [[alternative HTML version deleted]]
Hi Christa, The error messages tell you that the file contains NULL characters, which can cause problems with reading files. You can remove these characters with a "hex editor". I am not familiar with those used on Windows, but look at this Web page: http://alternativeto.net/software/okteta/?platform=windows The second error message simply tells you that there is no end-of-line on the final line of your file. Look at the file with the directory view "Details" and make sure that it is not an empty (zero byte) file. Jim On Fri, Jul 15, 2016 at 8:49 AM, Christa Rose <xarose at gmail.com> wrote:> Can someone please help? The read.table command is not working for me I > think because Windows has my account name stored as "Christa Rose" with a > space in it. Is this a problem? I have tried many syntax iterations, and > cannot get around this. > > Here is an example of the syntax I've used: >> RanMinePlay<-read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt",header=T) > And returned error messages: > in read.table("c:\\Users\\Christa Rose\\Desktop\\Ran_mine_play_data.txt", > : > empty beginning of file > In addition: Warning messages: > 1: In read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt", : > line 1 appears to contain embedded nulls > 2: In read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt", : > incomplete final line found by readTableHeader on 'c:\Users\Christa > Rose\Desktop\Ran_mine_play_data.txt > > Can someone help me resolve this?? > > Christa Rose > > > > *He is certain too that the cats, of whom there are many in the woods, have > a language of their own - some kind of old Irish. From "Enchanted > Woods", **William Butler Yeats* > > > > *It is in stone that the most abundant testimony is found of craftsmanship > in medieval Ireland. From Heritage of Ireland, **Brian de Breffny* > > [[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.
Duncan Murdoch
2016-Jul-15 00:32 UTC
[R] Please help: cannot import files from Windows into R
On 14/07/2016 6:49 PM, Christa Rose wrote:> Can someone please help? The read.table command is not working for me I > think because Windows has my account name stored as "Christa Rose" with a > space in it. Is this a problem? I have tried many syntax iterations, and > cannot get around this.I don't think that is the problem. The error message> > Here is an example of the syntax I've used: >> RanMinePlay<-read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt",header=T) > And returned error messages: > in read.table("c:\\Users\\Christa Rose\\Desktop\\Ran_mine_play_data.txt", > : > empty beginning of fileindicates that it found the file, but is confused by the content of it.> In addition: Warning messages: > 1: In read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt", : > line 1 appears to contain embedded nullsThis warning suggests that the file is not really a plain text file, but is some binary format, e.g. a file produced by Word or similar.> 2: In read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt", : > incomplete final line found by readTableHeader on 'c:\Users\Christa > Rose\Desktop\Ran_mine_play_data.txt > > Can someone help me resolve this??How did you produce the file Ran_mine_play_data.txt? If you saved it from Word, you need to tell it to save in plain Ascii format. I don't have a copy of Word to look at, so I can't tell you how that is described, but it is probably something like "Text (.txt)". Duncan Murdoch
John Dougherty
2016-Jul-15 01:13 UTC
[R] Please help: cannot import files from Windows into R
Christa, As others are noting, the file is not a text file. Open the file in Notebook or Notepad. If the editor complains, then open it in Word. Save it as a "plain text" file. You will have to choose the file type in the "Save As" dialog. You may run into other issues such as the field separator. It is best to limit the file to a header line containing any field names separated by commas or tabs, followed by columnar data, again with values separated by the same sepator used to separate the field names. Any metadata can be maintained in a separate text file. All of this presumes that your file came from Word or a compatible word processor. If it came from some other program and the "txt" type was simply by you added when you saved the file, we'll need to know what program the data was created in. -- John
William Dunlap
2016-Jul-15 03:50 UTC
[R] Please help: cannot import files from Windows into R
The file may have been stored in the UTF-16 encoding (what Windows Notepad calls "Unicode"). If so, adding fileEncoding="UTF-16" to the read.table command might read it correctly. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jul 14, 2016 at 3:49 PM, Christa Rose <xarose at gmail.com> wrote:> Can someone please help? The read.table command is not working for me I > think because Windows has my account name stored as "Christa Rose" with a > space in it. Is this a problem? I have tried many syntax iterations, and > cannot get around this. > > Here is an example of the syntax I've used: > > RanMinePlay<-read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt",header=T) > And returned error messages: > in read.table("c:\\Users\\Christa Rose\\Desktop\\Ran_mine_play_data.txt", > : > empty beginning of file > In addition: Warning messages: > 1: In read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt", : > line 1 appears to contain embedded nulls > 2: In read.table("c:\\Users\\Christa > Rose\\Desktop\\Ran_mine_play_data.txt", : > incomplete final line found by readTableHeader on 'c:\Users\Christa > Rose\Desktop\Ran_mine_play_data.txt > > Can someone help me resolve this?? > > Christa Rose > > > > *He is certain too that the cats, of whom there are many in the woods, have > a language of their own - some kind of old Irish. From "Enchanted > Woods", **William Butler Yeats* > > > > *It is in stone that the most abundant testimony is found of craftsmanship > in medieval Ireland. From Heritage of Ireland, **Brian de Breffny* > > [[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. >[[alternative HTML version deleted]]
Hi all, I need to aggregate some matrix data (1440x720) to a lower dimension (720x360) for lots of years and variables I can do double for loop, but that will be slow. Anybody know a quicker way? here an example with a smaller matrix size: tst=matrix(1:(8*4),ncol=8,nrow=4) tst_2x2=matrix(NA,ncol=4,nrow=2) nx=2 ny=2 for(ilon in seq(1,8,nx)) { for (ilat in seq(1,4,ny)) { ilon_2x2=1+(ilon-1)/nx ilat_2x2=1+(ilat-1)/ny tst_2x2[ilat_2x2,ilon_2x2] = mean(tst[ilat+0:1,ilon+0:1]) } } tst tst_2x2> tst[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1 5 9 13 17 21 25 29 [2,] 2 6 10 14 18 22 26 30 [3,] 3 7 11 15 19 23 27 31 [4,] 4 8 12 16 20 24 28 32> tst_2x2[,1] [,2] [,3] [,4] [1,] 3.5 11.5 19.5 27.5 [2,] 5.5 13.5 21.5 29.5 I though a cast to 3d-array might do the trick and apply over the new dimension, but that does not work, since it casts the data along the row.> matrix(apply(array(tst,dim=c(nx,ny,8)),3,mean),nrow=nrow(tst)/ny)[,1] [,2] [,3] [,4] [1,] 2.5 10.5 18.5 26.5 [2,] 6.5 14.5 22.5 30.5 cheers Peter