Save A Data Frame As CSV

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

#Save a data frame as CSV (Comma separated Value)

 
write.csv(d1,file=file.choose(new = TRUE))
 
d2 <- read.csv(file.choose(),row.names = 1)
#d2 <- read.csv(file.choose(),headers = FALSE,stringsAsFactors = TRUE, row.names = 1)
 
View(d2)
str(d2)
 

d2$Gender <- as.factor(d2$Gender)


 
#Use Xlsx pack for reading excel files
 
install.packages("xlsx") # installing pak
library(xlsx) # importing pack to current env
 
data2 <- read.xlsx(file.choose(),header = T,sheetIndex = 1,row.names=1 )
d1$Age <- as.integer(d1$Age)
 
summary(d1)
str(d1)
 
# Measure of Central Tendency   
mean(v2)
median(v2)
# based on Outlier analysis
#mode??
 
# Measure of Dispertion
sd(v2) & Mean - No outlier
QD & Median
QR
 
head(d1,3)
tail(d1,2)
nrow(d1)
ncol(d1)
 

#Rearranging Data (Data Tranfo)


 
install.packages("tidyr")
library(tidyr)
 
# gather, spread, separate, unite
 
?gather
 
gather(d1)
 
d3 <- gather(d1,Coln1,colmn2,Age:Gender) # Gather Colmns into key-Value
 
name Key     value
Abey Age      23
Abey Gender   M
Abey Mark     85
Boby Age      24
Boby Gender   M
 

spread(d3,Coln1,colmn2)  # reverse of Gather


 
d1$dob <- c('4-9-21','12-3-20','11-12-91','24-7-94','22-8-93','16-9-96')
View(d1)
 
d4 <- separate(d1,dob,c("Day","Month","Year"),sep="-")
 
unite(d4,DOB,Day,Month,Year,sep="/")
 
 
# Data Preprocessing Section
  # Data Cleaning
  # Data Transformation
# Data Model or Data Visualization

You might also like