[R] question

jim holtman jholtman at gmail.com
Thu Jul 2 03:03:55 CEST 2015


I forgot that you also wanted to change the variable name; I would suggest
that you don't use individual objects, but instead use a 'list'.  Here is
how it would change

result <- lapply(name_file$names, function(.file){
    result <- prep(z, .file)
    saveRDS(result, file = paste0(.file, '.RDS'))
    result  # return value that goes in the list
})



Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Wed, Jul 1, 2015 at 9:00 PM, jim holtman <jholtman at gmail.com> wrote:

> You never said how you wanted to save the data, so I will choose to use
> 'saveRDS' which should handle most anything.
>
> for (i in name_file$names){
>     saveRDS(prep(z, i),  file = paste0(i, '.RDS'))
> }
>
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
> On Wed, Jul 1, 2015 at 2:07 PM, Lida Zeighami <lid.zigh at gmail.com> wrote:
>
>> I have 682 variables in a data frame , and a function that  I should feed
>> 682 variables in this function one by one and each time save the file as a
>> special name!
>> for emaple:
>> my data frame file includes 682 names :
>> 1  aaa
>> 2  bbb
>> 3  dfdsfg
>> 4 fghh
>> .
>>
>> 682 fgfhg
>> and a function like prep(Z, aaa, .....) and each time I should change the
>> variable name in this function and read the variable from the data frame
>> and each time I should save the file as a special name such as:
>>
>> prep1<- prep(z, aaa,...)
>> prep2<- prep(z, bbb,...)
>> prep3<- prep(z, dfdsfg,..)
>> Prep4<- prep(z, fghh,...)
>>
>> How can I use loop function in R to that?
>>
>> Thanks
>>
>>         [[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]]



More information about the R-help mailing list