Data Journey

International Studies Grad. racing for AI Engineer

Download as .zip Download as .tar.gz View on GitHub
31 January 2021

Input/Output Files

by mervyn

source “K-MOOC 오세종 교수님의 [R 데이터 분석 입문] 강좌의 3-4. 파일에서 데이터 읽어오기/쓰기 중 (http://www.kmooc.kr/courses/course-v1:DKUK+DKUK0003+2020_T3)”

Import, Export Data from File

Excel .csv format read.csv(), write.csv()

setwd("C:\Rworks") # wd: working directory
mydata<- read.csv("test.csv", header=TRUE) # (FILENAME, header) check the column name of 1st row(header)
mydata # Entire data
head(mydata) # Front data
tail(mydata) # Back data
mydata[2,3] # element in row 2 column 3
nrow(mydata) # number of row
ncol(mydata) # number of columns
dim(mydata) # number of row and col

myRow1<- mydata[2,] # extract 2nd row data, create vector
myRow2<- mydata[,3] # extract 3rd column data, create vector

mynew<- mydata[,c(2,3)]
write.csv(mynew, "kid_new.csv", row.names=F, quote=F) # (variable name, FILENAME, no names for row, no "") Save data in file

mydata<- # without Setwd
read.csv("C:\FULL PATH TO FILE", header=TRUE) # Full path

mydata<-
read.csv(file.choose(), header= TRUE)# File Finder

Encoding Korean

FILENAME.csv(UTF-8)

setwd("C:\Rworks")
mydata<- read.csv("test.csv", header=TRUE, encoding= "utf-8")

Assignment

  1. Extract data of states with income equal or more than 5000 from state.x77 dataset, store in rich_state.csv

  2. Read rich_state.csv file and store in variable ds, print content of ds

data<- subset(state.x77, Income<=5000)
new<- data
write.csv(new, "rich_state.csv", row.names=F, quote=F)
ds<- read.csv("rich_state.csv", header=TRUE)
ds

back next

tags:

Comments

Post comment
Loading...

Share this: