[R] Loop over folder files
ruipbarradas at sapo.pt
ruipbarradas at sapo.pt
Wed Aug 24 19:18:14 CEST 2016
Maybe it's better to open a new thread.
Rui Barradas
Citando Juan Ceccarelli Arias <jfca283 at gmail.com>:
> The error wasn't in the loop. It was in the file list.
> It's running now because i added full.names option to TRUE
> fuente=list.files("C:/Users/Jceccarelli/Bases/Stata",
> pattern="dta$", full.names=T)
> Now R can proccess the data. Now it callapses or stops because other
> kind of error.
> ¿Should i open another topic or just use the mail list?
> By the way, thank you all.
>
> On Wed, Aug 24, 2016 at 11:48 AM, <ruipbarradas at sapo.pt> wrote:
>> _Hello,
>>
>> That means that probably the files are in a different folder/directory.
>> Use getwd() to see what is your current directory and
>> setwd("path/to/files") to set the right place where the files can be found.
>>
>> Rui Barradas
>> _
>>
>> _Citando Juan Ceccarelli Arias <jfca283 at gmail.com>:_
>>
>>> _I just doesn't work..._
>>> _Im loading the read,dta13 package already._
>>> _When i try to perform a simple table(sex), i received the "File
>>> not found" message._
>>> _However, if i load the data using the file.choose() option inside
>>> read.dta13, i can open the stata file._
>>> _I don't know what am i doing wrong..._
>>> _ _ _On Tue, Aug 23, 2016 at 5:08 PM, <ruipbarradas at sapo.pt> wrote: _
>>>> __Or maybe a print() statement on the table() in the loop.
>>>>
>>>> print(table(...))
>>>>
>>>> Rui Barradas
>>>> __
>>>>
>>>> __Citando David Winsemius <dwinsemius at comcast.net>:__
>>>>
>>>>>> __On Aug 23, 2016, at 10:01 AM, Juan Ceccarelli Arias
>>>>>> <jfca283 at gmail.com> wrote:
>>>>>>
>>>>>> Im running this but the code doesn't seem work.
>>>>>> It just hangs out but doesn't show any error.
>>>>>>
>>>>>> for (i in 1:length(fuente)){
>>>>>>
>>>>>> xxx=read_dta(fuente[i])
>>>>>>
>>>>>> table(xxx$cise, xxx$sexo)
>>>>>>
>>>>>> rm(xxx)
>>>>>>
>>>>>> }__
>>>>>
>>>>> __I still find the behavior of R's `for`-loop to be rather
>>>>> puzzling. In this case you appear to be getting the operation
>>>>> done, but because you didn't assign those table values to a
>>>>> variable they just disappeared.
>>>>>
>>>>> Try this:
>>>>>
>>>>> XXX <- list()
>>>>>
>>>>> for (i in 1:length(fuente)){
>>>>> xxx=read_dta(fuente[i])
>>>>> XXX[[i]] <- table(xxx$cise, xxx$sexo)
>>>>> rm(xxx)
>>>>> }
>>>>> str(XXX)
>>>>>
>>>>> Seems to me that if you can do assignment to the parent
>>>>> environment (without actually using assign( ..., env=...) that
>>>>> you should also be able to see the results of evaluation
>>>>> occurring inside the for loop, but for-loops return NULL. So you
>>>>> see nothing.
>>>>>
>>>>> David.
>>>>> _ _
>>>>>> __On Tue, Aug 23, 2016 at 6:31 AM, <ruipbarradas at sapo.pt> wrote:__
>>>>>>
>>>>>>> __Hello,
>>>>>>>
>>>>>>> The op could also use package sos to find that and other
>>>>>>> packages to read
>>>>>>> stata files.
>>>>>>>
>>>>>>> install.packages("sos")
>>>>>>>
>>>>>>> library(sos)
>>>>>>> findFn("stata")
>>>>>>> found 374 matches; retrieving 19 pages
>>>>>>> 2 3 4 5 6 7 8 9 10
>>>>>>> 11 12 13 14 15 16 17 18 19
>>>>>>> Downloaded 258 links in 121 packages
>>>>>>>
>>>>>>> The first package is readstata13 but there are others.
>>>>>>>
>>>>>>> Hope this helps,
>>>>>>>
>>>>>>> Rui Barradas
>>>>>>>
>>>>>>> Citando Michael Dewey <lists at dewey.myzen.co.uk>:
>>>>>>>
>>>>>>> Dear Juan
>>>>>>>
>>>>>>> If this is a Stata 13 file the package readstata13 available
>>>>>>> from CRAN may
>>>>>>> be of assistance.
>>>>>>>
>>>>>>> On 22/08/2016 18:40, Juan Ceccarelli Arias wrote:
>>>>>>>
>>>>>>> I removed the data,frame=True...
>>>>>>> I obtain this warnings...
>>>>>>> Error in read.dta(fuente[i]) : not a Stata version 5-12 .dta file
>>>>>>> In addition: There were 50 or more warnings (use warnings() to see the
>>>>>>> first 50)
>>>>>>>
>>>>>>> the warnings() throws this
>>>>>>> Warning messages:
>>>>>>> 1: In `levels<-`(`*tmp*`, value = if (nl == nL)
>>>>>>> as.character(labels) else
>>>>>>> paste0(labels, ... :
>>>>>>> duplicated levels in factors are deprecated
>>>>>>> 2: In `levels<-`(`*tmp*`, value = if (nl == nL)
>>>>>>> as.character(labels) else
>>>>>>> paste0(labels, ... :
>>>>>>> duplicated levels in factors are deprecated
>>>>>>> 3: In `levels<-`(`*tmp*`, value = if (nl == nL)
>>>>>>> as.character(labels) else
>>>>>>> paste0(labels, ... :
>>>>>>> duplicated levels in factors are deprecated
>>>>>>> 4: In `levels<-`(`*tmp*`, value = if (nl == nL)
>>>>>>> as.character(labels) else
>>>>>>> paste0(labels, ... :
>>>>>>> duplicated levels in factors are deprecated
>>>>>>> 5: In `levels<-`(`*tmp*`, value = if (nl == nL)
>>>>>>> as.character(labels) else
>>>>>>> paste0(labels, ... :
>>>>>>> duplicated levels in factors are deprecated
>>>>>>>
>>>>>>> On Mon, Aug 22, 2016 at 2:32 PM, <ruipbarradas at sapo.pt> wrote:
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> That argument doesn't exist, hence the error.
>>>>>>> Read the help page ?read.dta more carefully. You will see that already
>>>>>>> read.dta reads into a data.frame.
>>>>>>>
>>>>>>> Hope this helps,
>>>>>>>
>>>>>>> Rui Barradas
>>>>>>>
>>>>>>> Citando Juan Ceccarelli Arias <jfca283 at gmail.com>:
>>>>>>>
>>>>>>> Hi
>>>>>>> I need to apply some code over some stata files that are in folder.
>>>>>>> I've wrote this
>>>>>>>
>>>>>>> library(foreign)
>>>>>>>
>>>>>>> fuente=list.files("C:/Users/Jceccarelli/Bases/Stata[1]",
>>>>>>> pattern="dta$",
>>>>>>> full.names=FALSE)
>>>>>>>
>>>>>>> for (i in 1:length(fuente)){
>>>>>>>
>>>>>>> xxx=read.dta(fuente[i], to.data.frame=TRUE)
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> But i get this error
>>>>>>>
>>>>>>> Error in read.dta(fuente[i], to.data.frame = TRUE) :
>>>>>>> unused argument (to.data.frame = TRUE)
>>>>>>>
>>>>>>> What am i doing wrong?
>>>>>>>
>>>>>>> [[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.htmland provide commented, minimal, self-contained,
>>>>>>> reproducible code.
>>>>>>>
>>>>>>> [[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.
>>>>>>>
>>>>>>> --
>>>>>>> Michaelhttp://www.dewey.myzen.co.uk/home.html[1]
>>>>>>>
>>>>>>> _
>>>>>>
>>>>>> __[[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._
>>>>>
>>>>> _ _David WinsemiusAlameda, CA, USA__
>>>>
>>>> __ __
>>>
>>> _ _
>>> _ _
>>
>> _ _
Ligações:
---------
[1]
[[alternative HTML version deleted]]
More information about the R-help
mailing list