lecture_06

# lecture_06 - BIOS 735 Statistical Computing Michael Wu...

This preview shows pages 1–5. Sign up to view the full content.

BIOS 735: Statistical Computing Michael Wu Lecture 6: String Manipulation September 8, 2011 Michael Wu (Lecture 6) BIOS 735 September 8, 2011 1 / 12

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

View Full Document
String Manipulation R is not necessarily the best tool for doing string processing (manipulation of “character” types), but it’s often necessary: I Adjusting exported variable names to the R variable names I Changing categorical variable leveles I Processing text for use in L A T E X I Analysis of text based data I Data aquisition I Many other cases Recall that there really isn’t a “string” in R, but rather a “character” type. Michael Wu (Lecture 6) BIOS 735 September 8, 2011 2 / 12
String Manipulation: Basic Commands Coercion to a string a = 12345 b = as.character(a) String length: nchar nchar(b) British writer Susanna Clarke" nchar(a) nchar(12) nchar(1234) a = "" nchar(a) a = NA nchar(a) a = NULL nchar(a) Michael Wu (Lecture 6) BIOS 735 September 8, 2011 3 / 12

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

View Full Document
String Manipulation: Basic Commands Convert to UPPER/lower case: a = "UPPERlower" toupper(a) tolower(a) a = "UPPERlower3.14159_)({:;" toupper(a) Character translation: a = "butter" chartr("u","e", a) a = "BUTTER" chartr("u","e", a) old = c("BT") new = c("GN") chartr(old, new, a) chartr("T", "GN", a) chartr("TR", "N", a) Michael Wu (Lecture 6) BIOS 735 September 8, 2011 4 / 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

lecture_06 - BIOS 735 Statistical Computing Michael Wu...

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

View Full Document
Ask a homework question - tutors are online