[R] Dinamic variables in loop
Thierry Onkelinx
th|erry@onke||nx @end|ng |rom |nbo@be
Tue May 8 14:25:28 CEST 2018
Dear Laura,
It looks like you want to remove all rows for which each column is NA.
You can to that with the code below.
na.matrix <- is.na(MyData)
all.na.row <- apply(na.matrix, 1, all)
MyData[!all.na.row, ]
Best regards,
ir. Thierry Onkelinx
Statisticus / Statistician
Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx using inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be
///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////
2018-05-08 13:57 GMT+02:00 Laura Ringienė <lauraringiene using gmail.com>:
> Hello,
>
> I am a newbie in R and I have a problem.
> I want this line:
>
> newMyData <-MyData[!(is.na(col1)) | !(is.na(col2)) | !(is.na(col3)) | !(
> is.na(col4)) | !(is.na(col5)),]
>
> write in for loop. The number of col[number] may be different from 3 to 8
>
> Is there any ideas?
>
> Thank you
> Laura
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list