Hi, I'm new to R, so apologies in advance for the triviality of this question, but I was wondering if anyone could tell me why this function doesn't return the expected output, i.e. a matrix containing two columns from a large data frame called 'finalTable'? Oddly, the statement between the curly brackets works if run with 'thisCol' and 'thatCol' already defined. Any help would be much appreciated. Here's what 'finalTable' looks like, if it helps:- Many thanks, Adam -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-function-tp4630805.html Sent from the R help mailing list archive at Nabble.com.
Hello, There's nothing wrong with having 'thisCol' and 'thatCol' already defined or not. The problem is that your function does NOT return a value. Get rid of the assignment and it will work. CompFunct <- function(thisCol, thatCol) {cbind(finalTable[, thisCol], finalTable[, thatCol])} I would also include a data.frame argument, CompFunct2 <- function(x, thisCol, thatCol) {cbind(x[, thisCol], x[, thatCol])} CompFunct2(finalTable, 2, 3) (But the function is so simple that maybe it's purpose is to save some keystrokes.) Hope this helps, Rui Barradas acnunn wrote> > Hi, > > I'm new to R, so apologies in advance for the triviality of this question, > but I was wondering if anyone could tell me why this function doesn't > return the expected output, i.e. a matrix containing two columns from a > large data frame called 'finalTable'? Oddly, the statement between the > curly brackets works if run with 'thisCol' and 'thatCol' already defined. > Any help would be much appreciated. > > > > Here's what 'finalTable' looks like, if it helps:- > > > > Many thanks, Adam >-- View this message in context: http://r.789695.n4.nabble.com/Problem-with-function-tp4630805p4630808.html Sent from the R help mailing list archive at Nabble.com.
On May 21, 2012, at 5:13 PM, acnunn wrote:> Hi, > > I'm new to R, so apologies in advance for the triviality of this > question, > but I was wondering if anyone could tell me why this function > doesn't return > the expected output, i.e. a matrix containing two columns from a > large data > frame called 'finalTable'? Oddly, the statement between the curly > brackets > works if run with 'thisCol' and 'thatCol' already defined. Any help > would be > much appreciated. > >Nothing there.> > Here's what 'finalTable' looks like, if it helps:- > >Nothing to look at here, either. You have managed to find an even more obscure method of not presenting information than is usual for Nabble postings. -- David Winsemius, MD West Hartford, CT