[R] Determine the data type of a function to an argument
Francisco J. Zagmutt
gerifalte28 at hotmail.com
Tue Jun 20 23:46:06 CEST 2006
Look at ?class and perhaps is?. i.e.
x=c("1","2","3")
class(x)
[1] "character"
x=c(1,2,3)
class(x)
[1] "numeric"
I hope this helps
Francisco
Dr. Francisco J. Zagmutt
College of Veterinary Medicine and Biomedical Sciences
Colorado State University
>From: "Alex Restrepo" <alex_restrepo at hotmail.com>
>To: r-help at stat.math.ethz.ch
>Subject: [R] Determine the data type of a function to an argument
>Date: Tue, 20 Jun 2006 15:48:03 -0500
>
>Hello All:
>
>How can I determing the "types" of args passed to an R function? For
>example, given the following:
>
>
> calculate <- function(...)
> {
> args <- list(...)
> argName = names(args)
>
> if (arg1 == character)
> cat("arg1 is a character")
> else
> cat("arg1 is numeric")
>
>
> if (arg2 == character)
> cat("arg2 is a character")
> else
> cat("arg2 is a numeric")
>
> }
> value = calculate(arg1='222' arg2=333)
>
>Programatically, how can I determine if arg1 is a character and arg2 is
>numeric?
>
>Many Thanks:
>
>Alex
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
>http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list