Answers.Body: <p>EDIT: I'm editing my answer as I don't have comment privileges and don't wish to add multiple answers.</p>
  
  <p>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 <em>some</em> sense to people.</p>
  
  <p>Run <code>?sqrt</code> and check how the function is to be invoked, and how you're invoking it. Does it even accept 2 input parameters?</p>
  
  <hr>
  
  <h2>Original Content</h2>
  
  <p>You are subsetting the 2D object <code>data</code> improperly. How can data be subset as both <code>data[,1:6]</code> and <code>d[data[,1:24]]</code> where <code>d</code> = <code>data</code>? Fix that and your r code will work OK (syntactically at least).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T18:04:50.370Z
Answers.Text: 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
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T18:11:17.107Z
Answers.Text: 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.
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T18:13:46.297Z
Answers.Text: Hang on, in the first case you defined a function with 3 parameters and used just 1. What gives?
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T18:18:53.523Z
Answers.Text: Thank you but your comment about grep I could run the function and I edited my post
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T18:43:09.007Z
Answers.Text: `Why am I getting error` - the error is pretty explicit. The function is not being invoked properly.
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T18:00:23.187Z
Answers.LastActivityDate: 2019-01-12T18:56:12.030Z
Answers.LastEditDate: 2019-01-12T18:56:12.030Z
Answers.UserDisplayName: Ram RS
Body: <p>I have this matrix of expression data</p>
  
  <pre><code>&gt; 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
  &gt; 
  </code></pre>
  
  <p>I have 24 samples as cl1 and 30 samples as cl2</p>
  
  <p>I want to do a t.tset, I have this function but I am not sure Why I am getting error by </p>
  
  <pre><code>volcan &lt;- function(data, cl1, cl2) {
     tt &lt;- t(apply(data[, -1], 1, function(d){z &lt;- t.test(d[cl1], d[cl2]); c(z<span class="math-container">$estimate, z$</span>p.value)}))
       tt[, 1] &lt;- tt[, 1] - tt[, 2]
       tt &lt;- tt[, -2]
       tt &lt;- cbind(symbol=data[, 1], as.data.frame(tt), rank=NA)
       tt[, 3] &lt;- -log(tt[, 3], 10)
       colnames(tt)[2:3] &lt;- c("log.ratio", "neg.log(t.test)")
       tt[, 4] &lt;- sqrt(tt[, 2]^4  tt[, 3]^2)
       tt &lt;- tt[order(tt[, 4], decreasing=T), ]
       tt
  }
      Error: unexpected symbol in "tt[, 4] &lt;- sqrt(tt[, 2]^4 tt"
  </code></pre>
  
  <p>When I am running function as whole says that </p>
  
  <pre><code>Error: unexpected '}' in "}"
  </code></pre>
  
  <p>When I am putting </p>
  
  <blockquote>
    <p>tt= volcan(data,cl1,cl2) </p>
  </blockquote>
  
  <p>and doing line by line going down after </p>
  
  <pre><code>tt[, 4] &lt;- sqrt(tt[, 2]^4  tt[, 3]^2)
  </code></pre>
  
  <p>Says</p>
  
  <pre><code>Error: unexpected symbol in "tt[, 4] &lt;- sqrt(tt[, 2]^4  tt"
  </code></pre>
  
  <p>I am not sure why, I put comma in</p>
  
  <pre><code> tt[, 4] &lt;- sqrt(tt[, 2]^4 , tt[, 3]^2)
  </code></pre>
  
  <p>But another error</p>
  
Tags: <r><rna-seq>
Title: Changing this function to work
ThreadText: # Changing this function to work
  
  (Asked by: username_0 on 2019-01-12)
  
  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
  
  **Tags:** r, rna-seq
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-12. Score: 5
  
  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).
  
  > **Comments:**
  > **username_0**: 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  
  > **username_1**: 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.  
  > **username_1**: Hang on, in the first case you defined a function with 3 parameters and used just 1. What gives?  
  > **username_0**: Thank you but your comment about grep I could run the function and I edited my post  
  > **username_1**: `Why am I getting error` - the error is pretty explicit. The function is not being invoked properly.  
  
  ---
  
  