Vijaya Kumar Regati
2017-Jul-28 05:54 UTC
[R] R Programming help needed - Returning dataframes + 2 Variables dynamically
Hi, Can someone please help me on below issue I am facing : I am trying to play with returning a dataframe+2 variables using a fn. But facing an issue : Error in Logic_fn(c(x, y)) : argument "y" is missing, with no default This is the code I am using : x <- 0 y <- 0 Logic_fn <- function(x,y){ x <- x + 1 y < y + 1 test_data <- rbind(x,y) test_data <- data.frame(test_data) return(test_data) return(c(x,y)) } for ( i in 1:1) { test_data <- Logic_fn(c(x,y)) test_data[1] test_data[2] test_data } With Regards, Vijaya Kumar Regati Disclaimer: IMPORTANT NOTICE: This e-mail (including any attachments) are confidential, may contain proprietary or privileged information and is intended for the named recipient(s) only. If you are not the intended recipient, any disclosures, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this email in error, please notify the sender by return e-mail or telephone immediately and permanently delete the message and any attachments. [[alternative HTML version deleted]]
Berend Hasselman
2017-Jul-28 06:45 UTC
[R] R Programming help needed - Returning dataframes + 2 Variables dynamically
> On 28 Jul 2017, at 07:54, Vijaya Kumar Regati <VijayaKumar.Regati at m3bi.com> wrote: > > Hi, > > > Can someone please help me on below issue I am facing : > > > I am trying to play with returning a dataframe+2 variables using a fn. > But facing an issue : > > Error in Logic_fn(c(x, y)) : argument "y" is missing, with no default > > This is the code I am using : > > > x <- 0 > y <- 0 > > Logic_fn <- function(x,y){ > x <- x + 1 > y < y + 1Why only <? Shouldn't that be <- ?> test_data <- rbind(x,y) > test_data <- data.frame(test_data) > return(test_data) > return(c(x,y)) > } > > for ( i in 1:1) { > test_data <- Logic_fn(c(x,y))Use Logic_fn(x,y) instead of c(x,y), which is wrong.> test_data[1] > test_data[2] > test_data > > }You'll get other errors but you should really try to do some more analysing/debugging yourself. Berend hasselman
Jeff Newmiller
2017-Jul-28 06:45 UTC
[R] R Programming help needed - Returning dataframes + 2 Variables dynamically
A function MUST return one object. That one object may consist of a list of objects, but you have to separate the parts out after the function call yourself. -- Sent from my phone. Please excuse my brevity. On July 27, 2017 10:54:08 PM PDT, Vijaya Kumar Regati <VijayaKumar.Regati at m3bi.com> wrote:>Hi, > > >Can someone please help me on below issue I am facing : > > >I am trying to play with returning a dataframe+2 variables using a fn. >But facing an issue : > >Error in Logic_fn(c(x, y)) : argument "y" is missing, with no default > >This is the code I am using : > > >x <- 0 >y <- 0 > >Logic_fn <- function(x,y){ >x <- x + 1 >y < y + 1 >test_data <- rbind(x,y) >test_data <- data.frame(test_data) >return(test_data) >return(c(x,y)) >} > >for ( i in 1:1) { > test_data <- Logic_fn(c(x,y)) >test_data[1] >test_data[2] >test_data > >} > >With Regards, >Vijaya Kumar Regati > > >Disclaimer: IMPORTANT NOTICE: This e-mail (including any attachments) >are confidential, may contain proprietary or privileged information and >is intended for the named recipient(s) only. If you are not the >intended recipient, any disclosures, use, review, distribution, >printing or copying of the information contained in this e-mail message >and/or attachments to it are strictly prohibited. If you have received >this email in error, please notify the sender by return e-mail or >telephone immediately and permanently delete the message and any >attachments. > > [[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.
Possibly Parallel Threads
- R Programming help needed - Returning dataframes + 2 Variables dynamically
- R Programming help needed - Returning dataframes + 2 Variables dynamically
- R Programming help needed - Returning dataframes + 2 Variables dynamically
- Removing columns that are na or constant
- Passing date as parameter while retrieving data from database using dbGetQuery