[R] Help with a function [along columns]

Jim Lemon jim at bitwrit.com.au
Tue Oct 14 10:48:01 CEST 2014


On Mon, 13 Oct 2014 08:54:51 PM Kate Ignatius wrote:
> Just an update to this:
> 
> gtal <- function(d) {
>     alleles <- sapply(d, function(.) strsplit(as.character(.), "/"))
>     gt <- unlist(lapply(alleles, function(x)
>            ifelse(identical(x[[1]], vcf[,3]) & identical(x[[2]], vcf[,3]),
> 'RR', ifelse(identical(x[[1]], vcf[,4]) & identical(x[[2]], vcf[,4]), 'AA',
> ifelse(identical(x[[1]], vcf[,3]) & identical(x[[2]], vcf[,4]), 'RA',
> ifelse(identical(x[[1]], vcf[,4]) & identical(x[[2]],
> vcf[,3]), 'RA', ''))))))
> }
> 
> I've got something working but I'm having trouble with the gt part...
> I'm getting the error: object of type 'closure' is not subsettable.
> The vcf is my original file that I want to match with so not sure
> whether this a problem.
> 

Hi Kate,
Unless you have passed "vcf" to your function, it is unlikely to recognize 
it. As you are working with genome data, I suspect that there is a 
function named "vcf" somewhere in the parent environment and you 
can't subset a function.

Jim



More information about the R-help mailing list