Hi I have the data with 2 columns, name and salary. There are total 12 names and For each name there are 48 rows of salary I have splitted the data*(data has 48 rows for each name)* so that I got separate blocks of data for each name (likewise I got 12 blocks) Now I want to convert each block of data into a 4R and 12C matrix and write that each block to a .pdf or .doc file please tell me if it works in this direction or shud I try another way?
Asked
Active
Viewed 152 times
2
-
1Could you please add some reproducible code? And what exactly do you mean with writing it to a pdf or doc file? If you want a table, you'll have to use eg xtable() and latex to automize things. Or Sweave, which is combining R and latex. Then you get it into a table. But you'll have to know latex – Joris Meys Aug 10 '11 at 15:56
-
test<-read.csv("emp.csv",sep=',') split(test,test$name) I got blocks of data splitted with this. And I basically want the resultant 4R and 12C matrices to be written to a file (.csv or .txt if possible .pdf), sorry if I confused you. I am relatively new to R and I dont have the idea of latex – Matt Aug 10 '11 at 16:00
-
With reproducible, I mean reproducible in this way : http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Joris Meys Aug 10 '11 at 16:03
-
you want everything in one file, or you want them in different files? – Joris Meys Aug 10 '11 at 16:37
-
I am looking for each block into a different file..can you please suggest me a way to write into a different file – Matt Aug 10 '11 at 17:17
1 Answers
0
If you know latex, you can use xtable as explained in my comment. This will give you latex code for a table that you can copy-paste in your editor (or send to a text file, see the help files). So what you do can be done as :
# some sample data, please give us that next time you post a question
myframe <- data.frame(
name=rep(letters[1:3],each=48),
salary=runif(48*3,1000,2000)
)
# make the matrices
mylist <- tapply(myframe$salary, myframe$name,matrix,nrow=4,byrow=T)
# make some tables. If you want to format them, see the help files
require(xtable)
lapply(mylist,xtable)

Joris Meys
- 106,551
- 31
- 221
- 263
-
I am sorry I would post the sample data from next time onwards. This works for me as I could make a 4R and 12C matrix,but I have problem in writing the data to a file... – Matt Aug 10 '11 at 17:12
-
I am able to write each block into a text file, but when I put it in a for loop its not working – Matt Aug 10 '11 at 21:55
-
Put the code you tried up as a new question, so we can tell you why it is not work. And make sure to include a reproducible example. For all I care, you can copy my code into your own question to reconstruct a list. – Joris Meys Aug 11 '11 at 11:41