The assignment is as follows.
Q2. Write a function with one argument, say, data
.
The function does following,
data
.I am very new to this and would like to use basic R code to solve it. I don't really understand the syntax I ought to use.
You may want to upload some data examples. I am assuming your 'data' is pure character or numbers. See code below. But detailed information will be needed if it does not work for you.
myfunc=function(data){
if(is.character(data)){
res=list(data=data, Nchar=sum(nchar(data)))
}
else if(is.numeric(data)){
res=list(data=data, mean=mean(data), sd=sd(data),max=max(data), min=min(data))
}
return(res)
}
#usage
data1=c("a","bbb")
myfunc(data1)
data2=c(1,2,3)
myfunc(data2)