Chapter4 - Chapter 4 Chapter 4 4.1 R Export/Import Data...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 4 R - 1 - Chapter 4 Export/Import Data 4.1 Data Export a. The function cat is useful for producing output in user-defined functions. > cat("Good morning!","\n") #\n: newline Good morning! > cat(file="K:\\6360\\Rdata\\test.txt", "123456", "987654", sep="\n") Note that "K:\\" in the file path is not a mistake. b. The function print prints its argument. It is a generic function which means that new printing methods can be easily added for new classes. > print("Good morning!") [1] "Good morning!" c. The commonest task is to write a matrix or data frame to file as a rectangular grid of numbers, possibly with row and column labels. This can be done by the functions write.table and write . i. Command to copy and paste from R into Excel or other programs. It writes the data of an R data frame object into the clipboard from where it can be pasted into other applications. > age=18:29 > height=c(76.1,77,78.1,78.2,78.8,79.7,79.9,81.1, 81.2,81.8,82.8,83.5) > village=data.frame(age=age,height=height)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter 4 R - 2 - > write.table(village, "clipboard", sep="\t", col.names=NA, quote=F) #Write village into clipboard Remark: (i) The argument quote is a logical value ( TRUE or FALSE ) or a numeric vector. If TRUE , any character or factor columns will be surrounded by double quotes. If FALSE , nothing is quoted. (ii) The argument 'col.names= NA' makes sure that the titles align with columns when row/index names are exported (default). ii. Write data frame to a tab-delimited text file. > write.table(village, file="K:\\6360\\Rdata\\village.txt", sep="\t", col.names= NA, quote=F) iii. Write matrix data to a file. > x = matrix(1, 20, 20)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/06/2011 for the course STAT 4360 taught by Professor Park during the Spring '11 term at University of Georgia Athens.

Page1 / 8

Chapter4 - Chapter 4 Chapter 4 4.1 R Export/Import Data...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online