티스토리 뷰

R

Python

 

search()

ls()

ls(pos=2)

 

dir(__builtins__)

 

help(abs)

?abs

 

help(abs)

 

5 %% 2

7 %% 3

 

5 % 2

7 % 3

 

increment=function(x) { x+1 }

 

def increment(x):

    return x+1

 

sent = "I'm feeling good."

sent = "I\'m feeling good."

sent = 'I\'m feeling good.‘

 

sent = "I\'m feeling good."

sent = "I'm feeling good."

sent = 'I\'m feeling good."

 

print(paste(c("ba",rep("na",2),

           "muffin."), collapse=""))

 

print("ba"+"na"*2+"muffin.")

 

age=readline("How old are you?")

#cat("How old are you?")

#age=scan(what=numeric(), nmax=1)

 

age=input("How old are you?")

comp=function(n) {

ifelse(n>100, "More than 100.", ifelse(n>10, "10<n<=100.","n<=10."))

}

 

def comp(n):

    if n>100:

        return "More than 100."

    elif n>10:

        return "More than 10, but equal to or less than 100."

    else:

        return "Equal to or less than 10.“

 

 

grepl('mile','smiles')

grepl('smiles','mile')

 

'mile' in 'smiles'

'smiles' in 'mile'

 

nchar('Hello')

 

len('Hello')

 

s='Call Me Maybe'

substring(s, 13, 13)    

# in R, index starts from 1

substring(s, nchar(s), nchar(s))

 

substring(s, 1, 4)

 

paste(substring(s, 1, nchar(s)-5),"Perhaps",sep="")

 

s='Call Me Maybe'

s[12]

s[-1]

 

s[:4]

 

s=s[:-5]+'Perhaps'

s=s[0:-5]+'Perhaps'

 

regexpr("function",s)    # s.find("function")

length(gregexpr("function",s)[[1]]) # s.count("function")

tolower(s)

 

s.find("function")

s.count("function")

s.lower()

 

for (vowel in c('a','e','i','o','u'))

{ print(vowel) }

 

for vowel in 'aeiou':

    print(vowel)

num=6

while (num>0) {

print(num); num=num-1 }

 

num=6

while num>0:

    print(num)

    num=num-1

 

 

temperature = list(18, 20, 22.5, 24)

temperature[[4]]

temperature[4]

 

temperature = [18, 20, 22.5, 24]

temperature[3]

temperature[3:]

 

length(list("math"))

nchar("math")

 

len(["math"])

len("math")

 

grades=list(80, 90, 70)

grades <- c(grades, 3) #grades[[length(grades)+1]] = 3

grades[[length(grades)]];

grades[[length(grades)]]=NULL

grades2=list(99, 77);

append(grades, grades2)

grades[grades == 70] = NULL

 

grades=[80, 90, 70]

grades.append(3)

grades.pop()

grades.extend([99,77])

grades.remove(70)

 

 

grades=list(80,70,60,90)

grades=as.list(sort(unlist(grades)))

 

grades.sort()

 

seq(1,10,2)     # range(1,10,2)

lst=list(1,2,3)

seq(lst)         # range(len(lst))

 

range(1,10,2)

lst=[1, 2, 3]

range(len(lst))

 

lst=list(list(10,20),list(15),list(40,22))

total=0

for (sublist in lst) {

for (num in sublist) total=total+num }

 

 

lst=[[10,20],[15],[40,22]]

total=0

for sublist in lst:

        for num in sublist:

                total=total+num

 

 

cat_string = readLines("cat.txt")

cat_string = paste(cat_string, collapse="\n")

 

cat_file = open("cat.txt", "r")

cat_string= cat_file.read()

getwd()

 

import os

os.getcwd()

 

setwd("tempDir")

 

import os

os.chdir("tempDir")

 

 

 

tyImmutableList = (2, 3, 5)

tyDict = {'a':1, 2:'b'}

 


'차기작 : R을 배우자' 카테고리의 다른 글

R studio, Git, BitBucket  (0) 2014.02.25
frequency polygons  (0) 2014.02.22
Python and R  (0) 2014.02.15
and R  (0) 2014.02.15
Python  (0) 2014.02.15
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함