Re: [R] Determine the data type of a function to an argument

From: Francisco J. Zagmutt <gerifalte28_at_hotmail.com>
Date: Wed 21 Jun 2006 - 07:46:06 EST


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@hotmail.com>
>To: r-help@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@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



R-help@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 Received on Wed Jun 21 07:55:22 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 21 Jun 2006 - 10:11:37 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.