Error: object not found - Second loop
1
0
Entering edit mode
3.4 years ago
kbaitsi • 0

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 • 794 views
ADD COMMENT
0
Entering edit mode

Why are you using c(i:i)?

ADD REPLY
3
Entering edit mode
3.4 years ago
Sam ★ 4.7k

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 COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2700 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6