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.

______________________________________________
R-help@r-project.org 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.

Reply via email to