Error: unexpected '=' in:

results<-list()
for(i in unique(g,g$`cancer type abbreviation`)){
  z<-subset(g,g$`cancer type abbreviation`= i)
  z<-z$sample
  new.m<-m[m$sample % in % z,]
  important.value <-mean(new.m$RNAss)
  results[(i)] <-important.value
}

When I run this loop, I'm getting following error continuously. Plz help me to solve it.

> results<-list()
> for(i in unique(g,g$`cancer type abbreviation`)){
+   z<- subset(g,g$`cancer type abbreviation`= i)
Error: unexpected '=' in:
"for(i in unique(g,g$`cancer type abbreviation`)){
  z<- subset(g,g$`cancer type abbreviation`="

Testing for equality would be done by using ==

Thank you very much. It worked

Loop runs and again error appears, Actually, I'm very new for R coding.

> results<-list()
> for(i in unique(g,g$`cancer type abbreviation`)){
+   z<- subset(g,g$`cancer type abbreviation`== i)
+   z<- z$sample
+   new.m<-m[m$sample % in % z,]
+   important.value <-mean(new.m$RNAss)
+   results[(i)] <-important.value
+ }
Error: argument 'incomparables != FALSE' is not used (yet)
> View(results)

Are you missing backticks in cancer type abbreviation?

No, The following issue is still persists.
Error: argument 'incomparables != FALSE' is not used (yet)

The second argument of unique is a vector of values that never count as duplicated. Is that your intention?

Yes, I have 12,000 data samples, which are belongs to 33 Cancer types. intention is to group all based on cancer types. So, I should get 33 lists.

I'm not sure whether unique is what you want. Unless some of the rows in g are identical, unique is going to give you back g. Wouldn't that be 12,000 rows rather than 33?

Perhaps you dput() to post a piece of your data and tell us what you are looking for out of that piece.

Yes, my goal is to separate 12,000 patients data based on 33 cancer types.

I think startz is correct that this is wrong.
, and should be

for(i in unique(g$`cancer type abbreviation`))
1 Like

Thank you for all of your support. It worked now. The worked coding:

results<-list()
for(i in unique(g$cancer type abbreviation)){
z<- subset(g,g$cancer type abbreviation==i)
z<- z$sample
new.m<-m[m$sample %in% z,]
important.value <-mean(new.m$RNAss)
results[(i)] <-important.value
}

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.