lungdata <- read.table(file.choose(), header=TRUE) # pd.read_text
head(lungdata) # df.head
tail(lungdata) # df.tail
lungdata2 <- read.csv(file.choose(), header = T) #pd.read_csv
head(lungdata2)
tail(lungdata2)
str(lungdata2)
max(lungdata2Heights)
roll <- 10000000
n <- 6
dice <- ceiling(runif(roll) * n)
a <- table(die)
barplot(a)
roll <- 1000
dice <- ceiling(runif(roll) 6) + ceiling(runif(roll) 6) #round()
a <- table(dice)
barplot(a) # plt.bar()
a[7]
install.packages("tidyr") #pip.install
install.packages("dplyr")
library(tidyr) #import
library(dplyr)
member <- data.frame(family = c(1,2,3), namef = c('a','b','c'),
agef = c(30,40,50), namem = c('d','e','f'), agem = c(44,53,25)) # pd.dataframe
member
a <- gather(member, key, value, namef:agem) # 값들을 길게 아래로 뿌려줌, unstack
a
b <- separate(a, key, c('variable', 'type'), -1) # key 값을 comma 뒤 기준으로 하여 두 가지로 쪼갬
b
new <- spread(b, variable, value) # stack
new
new2 <- member %>% # pipeline
gather(key, value, namef:agem) %>%
separate(key, c('variable', 'type'), -1) %>%
spread(variable, value)
new2
filter(new, age >= 30)
select(member, family, namef, agef)
x <- 'what is your name?'
x <- "what's your name?"
x
y <- character()
y
length(y)
y2 <- ""
class(y) # type()
class(y2)
length(y2)
y <- c('e', '12', '2')
y <- character(10)
length(y)
y[3] <- "Third"
y[12] <- "Twelves"
length(y)
y[11] <- "11"
y
n = 3
m = "3"
is.character(n) # 문자형인지 확인
is.character((m))
class(n)
class(m)
as.character(n) # 문자처럼 표현, 실제로 변경은 아님
class(n)
t <- c(1:5)
t2 <- c(1:5, "a")
t2 # 형식이 모두 같아야 하기에 모두 문자형으로 변경됨.
class(t)
class(t2)
t3 <- c(1:4, TRUE, FALSE) # True는 1 False는 0
t3
class(t3)
t4 <- c(1:4, TRUE, FALSE, "a")
class(t4)
df1 <- data.frame(n=c(1:4, "a"), letters=c('a','b','c','23','1'))
df1
str(df1)