Question: Error: object not found - Second loop
0
gravatar for kbaitsi
7 weeks ago by
kbaitsi0
kbaitsi0 wrote:

I have a tsv file with 61 columns and 18703 lines. I have written the following code:

f<-read.table(file = "GeneExpressionDataset_normalized.tsv", sep="\t", header=TRUE)
m<-as.data.frame(f)
m

for (i in 1:nrow(m)){
  wt[i]<-c(sum(m[c(i:i),c(2:11)]))/10
}
wt

for (i in 1:nrow(m)){
  TherA[i]<-c(sum(m[c(i:i),c(22:31)]))/10
}
TherA

For some reason the first loop works but the second one produces Error Subject not found. The loops are identical in syntax. What could be wrong?

loop R • 115 views
ADD COMMENTlink modified 7 weeks ago by Sam3.3k • written 7 weeks ago by kbaitsi0

Why are you using c(i:i)?

ADD REPLYlink written 7 weeks ago by Alex Reynolds31k
3
gravatar for Sam
7 weeks ago by
Sam3.3k
New York
Sam3.3k wrote:

what you want might be instead

f <- read.table(file = "GeneExpressionDataset_normalized.tsv", sep="\t", header=TRUE)
wt <- apply(f[,2:11], 1, mean)
TherA <- apply(f[,22:31], 1, mean)

(I am guessing that you are looking for the mean of each group for each row)

ADD COMMENTlink written 7 weeks ago by Sam3.3k

Yes, this was my intention. Your way seems more suitable. Thank you!

ADD REPLYlink written 7 weeks ago by kbaitsi0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 980 users visited in the last hour