HI, Michael,
I tried use x and got the following:
> for (i in 2:3) {
+
+ assign(x=paste("array", i, sep=""), value=result.fun[[i-1]])
+
+ first <-cbind(first, x)
+
+ }
*Error in cbind(first, x) : object 'x' not found
*
But I checked the
ls()
"array2" "array3" were created.
Can I put them into the first data set by loop, or manually?
Thanks!
P.S I search the similar codes from google and can not work as I expected.
Thanks!
On Thu, Sep 22, 2011 at 10:11 AM, R. Michael Weylandt <
[email protected]> wrote:
> There is no "lab=" argument for assign() hence the error. Did someone
> provide you with example code that suggested such a thing? remove lab=
> entirely or replace it with x= to make your code work. More generally type
> ?assign or args(assign) to see what the arguments for a function are.
>
> More generally, this sort of thing may be best handled in a list rather
> than an set of independent variables.
>
> Michael Weylandt
>
> On Thu, Sep 22, 2011 at 1:07 PM, Changbin Du <[email protected]> wrote:
>
>> HI, Dear R community,
>>
>> I am trying to created new variables and put into a data frame through a
>> loop.
>>
>> My original data set:
>>
>> head(first)
>> probe_name chr_id position array1
>> 1 C-7SARK 1 849467 10
>> 2 C-4WYLN 1 854278 10
>> 3 C-3BFNY 1 854471 10
>> 4 C-7ONNE 1 874460 10
>> 5 C-6HYCN 1 874571 10
>> 6 C-7SCGC 1 874609 10
>>
>>
>> I have 48 other array data from a list result.fun
>> array2=result.fun[[1]]
>> array3=result.fun[[2]]
>> .
>> .
>>
>> I want the following results:
>>
>> probe_name chr_id position array1 array2 array3
>> 1 C-7SARK 1 849467 10 10 10
>> 2 C-4WYLN 1 854278 10 10 10
>> 3 C-3BFNY 1 854471 10 10 10
>> 4 C-7ONNE 1 874460 10 10 10
>> 5 C-6HYCN 1 874571 10 10 10
>> 6 C-7SCGC 1 874609 10 10 10
>>
>>
>> I used the following codes:
>>
>> for (i in 2:3) {
>>
>> assign(lab=paste("array", i, sep=""), value=result.fun[[i-1]])
>>
>> first <-cbind(first, lab)
>>
>> }
>>
>> *Error in assign(lab = paste("array", i, sep = ""), value = result.fun[[i
>> -
>> :
>> unused argument(s) (lab = paste("array", i, sep = ""))*
>>
>>
>> Can anyone give some hits or helps?
>>
>> Thanks so much!
>>
>>
>>
>>
>>
>>
>> --
>> Sincerely,
>> Changbin
>> --
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [email protected] mailing list
>> 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.
>>
>
>
--
Sincerely,
Changbin
--
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
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.