-2
$\begingroup$

I have this matrix of expression data

> head(data[,1:6])  Symbol      cl1    cl1.1     cl1.2     cl1.3    cl1.41   ACTB 14.07922 14.25211 13.547206 14.046814 15.335512 ATP5F1 10.43386 10.34219  9.671036  9.862641 10.397863   DDX5 13.99250 13.29734 13.706894 13.084000 13.733794  EEF1G 14.35303 14.26112 13.523434 13.327333 13.977475  GAPDH 16.07695 15.61435 15.454911 15.233670 15.901006    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

askedJan 12, 2019 at 17:54
Zizogolu's user avatar
$\endgroup$

1 Answer1

5
$\begingroup$

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 makessome 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 objectdata improperly. How can data be subset as bothdata[,1:6] andd[data[,1:24]] whered =data? Fix that and your r code will work OK (syntactically at least).

answeredJan 12, 2019 at 18:00
Ram RS's user avatar
$\endgroup$
5
  • $\begingroup$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$\endgroup$CommentedJan 12, 2019 at 18:04
  • $\begingroup$Usegrepl on thecolnames(d) to pick relevant columns and then subset by the results of thegrepl. You should really Google this stuff.$\endgroup$CommentedJan 12, 2019 at 18:11
  • $\begingroup$Hang on, in the first case you defined a function with 3 parameters and used just 1. What gives?$\endgroup$CommentedJan 12, 2019 at 18:13
  • $\begingroup$Thank you but your comment about grep I could run the function and I edited my post$\endgroup$CommentedJan 12, 2019 at 18:18
  • $\begingroup$Why am I getting error - the error is pretty explicit. The function is not being invoked properly.$\endgroup$CommentedJan 12, 2019 at 18:43

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.