Skip to content

Instantly share code, notes, and snippets.

@cecilialee
Last active February 13, 2018 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecilialee/d096b34725a4ceb187586c24e9c0f5e2 to your computer and use it in GitHub Desktop.
Save cecilialee/d096b34725a4ceb187586c24e9c0f5e2 to your computer and use it in GitHub Desktop.
Compare common util functions in Python and R. #python #r

Concatenate strings

## py ##
a = 'Data Science'
b = '!'

'{}{}'.format(a, b)
#[1] 'Data Science!'
## r ##
a <- "Data Science"
b <- "!"

paste0(a, b)
#[1] "Data Science!"

Subset a string

## py ##
abc = 'abcdefg'
abc[:3]
#[1] 'abc'
## r ##
abc <- "abcdefg"
substr(abc, 1, 3)
#[1] "abc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment