On Jun 23, 2015, at 3:20 PM, boB Rudis wrote:
> You can do something like:
>
> aaa <- function(data, w=w) {
> if (class(w) %in% c("integer", "numeric", "double")) {
I think you will find that inherits(w, "numeric") is more compact and safer.
Both "integer" and "double" do inherit from "numeri
: boB Rudis
Cc: r-help mailing list
Subject: Re: [R] Call to a function
Thanks! From this I learn the much needed class statement
if (class(wt)=="character") wt <- x[, wt]
which serves my need in a bigger project.
Steven Yen
On 6/23/2015 6:20 PM, boB Rudis wrote:
> You
?with
e.g. with(mydata,aaa(v1))
-- Bert
Bert Gunter
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
-- Clifford Stoll
On Tue, Jun 23, 2015 at 2:39 PM, Steven Yen wrote:
> Dear Members
> I have a data frame as generated below. I like to be abl
Thanks! From this I learn the much needed class statement
if (class(wt)=="character") wt <- x[, wt]
which serves my need in a bigger project.
Steven Yen
On 6/23/2015 6:20 PM, boB Rudis wrote:
You can do something like:
aaa <- function(data, w=w) {
if (class(w) %in% c("integer", "numer
You can do something like:
aaa <- function(data, w=w) {
if (class(w) %in% c("integer", "numeric", "double")) {
out <- mean(w)
} else {
out <- mean(data[, w])
}
return(out)
}
(there are some typos in your function you may want to double check, too)
On Tue, Jun 23, 2015 at 5:39 PM,
Dear Members
I have a data frame as generated below. I like to be able to call a
function both with a vector and a vector (mydata$v1) in that data frame
(v1). The first call works, but the second does not. Can someone help me
with the second call? Thanks!!
---
mydata<-data.frame(matrix(1:20,ncol=
6 matches
Mail list logo