# Changing this function to work

I have this matrix of expression data

> head(data[,1:6])
Symbol      cl1    cl1.1     cl1.2     cl1.3    cl1.4
1   ACTB 14.07922 14.25211 13.547206 14.046814 15.33551
2 ATP5F1 10.43386 10.34219  9.671036  9.862641 10.39786
3   DDX5 13.99250 13.29734 13.706894 13.084000 13.73379
4  EEF1G 14.35303 14.26112 13.523434 13.327333 13.97747
5  GAPDH 16.07695 15.61435 15.454911 15.233670 15.90100
6    NCL 14.35149 13.32919 13.051861 12.704973 13.55680
>


I have 24 samples as cl1 and 30 samples as cl2

I want to do a t.tset, I have this function but I am not sure Why I am getting error by

volcan <- function(data, cl1, cl2) {
tt <- t(apply(data[, -1], 1, function(d){z <- t.test(d[cl1], d[cl2]); c(z$$estimate, z$$p.value)}))
tt[, 1] <- tt[, 1] - tt[, 2]
tt <- tt[, -2]
tt <- cbind(symbol=data[, 1], as.data.frame(tt), rank=NA)
tt[, 3] <- -log(tt[, 3], 10)
colnames(tt)[2:3] <- c("log.ratio", "neg.log(t.test)")
tt[, 4] <- sqrt(tt[, 2]^4  tt[, 3]^2)
tt <- tt[order(tt[, 4], decreasing=T), ]
tt
}
Error: unexpected symbol in "tt[, 4] <- sqrt(tt[, 2]^4 tt"


When I am running function as whole says that

Error: unexpected '}' in "}"


When I am putting

tt= volcan(data,cl1,cl2)

and doing line by line going down after

tt[, 4] <- sqrt(tt[, 2]^4  tt[, 3]^2)


Says

Error: unexpected symbol in "tt[, 4] <- sqrt(tt[, 2]^4  tt"


I am not sure why, I put comma in

 tt[, 4] <- sqrt(tt[, 2]^4 , tt[, 3]^2)


But another error

EDIT: I'm editing my answer as I don't have comment privileges and don't wish to add multiple answers.

Please don't change the entire premise of the question after you get an answer. If you do, retain the original content so the post makes some sense to people.

Run ?sqrt and check how the function is to be invoked, and how you're invoking it. Does it even accept 2 input parameters?

## Original Content

You are subsetting the 2D object data improperly. How can data be subset as both data[,1:6] and d[data[,1:24]] where d = data? Fix that and your r code will work OK (syntactically at least).

• Sorry, instead how I can define c1l and cl2 classes for first function so I don't have to subset data manually in second function – Angel Jan 12 at 18:04
• Use grepl on the colnames(d) to pick relevant columns and then subset by the results of the grepl. You should really Google this stuff. – Ram RS Jan 12 at 18:11
• Hang on, in the first case you defined a function with 3 parameters and used just 1. What gives? – Ram RS Jan 12 at 18:13
• Thank you but your comment about grep I could run the function and I edited my post – Angel Jan 12 at 18:18
• Why am I getting error - the error is pretty explicit. The function is not being invoked properly. – Ram RS Jan 12 at 18:43