Off topic:R for loop trouble with paste0 an variable assignment
0
0
Entering edit mode
7.2 years ago
Neuls ▴ 20

Hi,

I'm trying to loop through a string vector called iter in order to subset a data frame in R. I would like to filter that data frame using i iter value in the loop and assign it to a variable using iter value i. however, it wasnt working I think variable assignment is not properly done.

 for ( i in iter) {
      paste0(i)<-subset(out,TestId==paste0(i) & AddId=="Curve_F_Cor")
    }

I have tried with assign built in R function but i havent and seems to work

for ( i in iter) {
  assign(i, subset(out,TestId==paste0(i) & AddId=="Curva_F_Cor"))
}

I have read several times that using assign in this way is not very nice. I've read about lapply but i cannot figure out how to use it Which one would be the best option to do it?

Thanks

R for paste0 • 7.0k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2437 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