There does not seem to be a function exactly similar to MATLAB's "fprintf" in R, but you can achieve pretty much the same results using something like the code below:

a <- 1:10
b <- 11:20
ab <- cbind(a,b)
sink("C:\\R\\test.txt")  # open file to write data to - file will be deleted if it exists
cat(paste("The number is: ", 5, "\n", sep=""))
sprintf("The dimensions of matrix ab is: %i x %i", dim(ab)[1], dim(ab)[2])                      # compare with the line below
cat(sprintf("The dimensions of matrix ab is: %i x %i", dim(ab)[1], dim(ab)[2]),"\n")  # compare with the line above
cat(sprintf("%s is %f feet tall", "Sven", 7.1),"\n")
sink()                   # close file
# do more stuff
# append to previous file
sink("C:\\R\\test.txt", append=TRUE)  # open file for appending
cat("\n")
cat("Test in appending\n")
sink()                                # close file

You wrote:

Dear All,



Currently, I am translating Matlab code to R. I met difficulties to translate such Matlab codes into R:

fprintf(fid,(' SPLITTING RESULTS '));

fprintf(fid,(' \n'));

fprintf(fid,' Data base to analyze is a matrix %4i x %2i ',[n m]);

fprintf(fid,' \n');

fprintf(fid,' h is %2i',h);

fprintf(fid,' \n');

fprintf(fid,' group=0 outlier.\n');

fprintf(fid,' group=-1 discriminator or observation removed by the rules.\n');

fprintf(fid,' \n');



Does anyone happen to know if R has similar function as fprintf in Matlab?



Thanks a lot!



Best

Zunqiu


Jude Ryan
Director | MarketShare
1270 Avenue of the Americas, Suite # 2702, New York, NY 10020
P: 646.745.9916 x222 | M: 973.943.2029
www.marketshare.com
twitter.com/marketshareco

This email message is for the sole use of the intended r...{{dropped:10}}

