In R, I would like to create a loop that takes the first 3000 columns of my data frame and writes them to one file, the next 3000 columns to another file, etc. etc. until all columns are separated as such. What would be the best way to do this? I understand that isplit and iterators functions are now available through CRAN, but I'm really not sure how to do this. Any suggestions please?
You can try something like:
library(plyr) max.col <- ncol(x) l_ply(seq(1, max.col, by=3000), function(i) write.table(x[,i:min(i+2999, max.col)], file=paste("i", i, sep="-")) )
Not sure why you need to load plyr ... if your df data frame ... (stole the wise use of min () from Shane's answer)
maxCol <- ncol(df) for (i in seq(1, maxCol, by 3000)) { write.table(df[,i:min(i+2999, maxCol)], "i") }
write.table , .
Source: https://habr.com/ru/post/1753386/More articles:Prevent PHP from executing require_once - phpWhy am I getting an Unhandled Exception: System.IO.IOException when I try to read from the file it is written to? - c #php xpath: request as a result of the request - phpParse the email address in Oracle to count the number of addresses with 3 or less characters before the @ sign - sqlMySQL order by rand () grouped by day - mysqlTemplate for using IEnumerator in interfaces - c #How to listen for DLL function calls - c ++Combobox with multiple columns - c #response.redirect not working - c #Windows Python command line version - pythonAll Articles