-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSVfile.R
59 lines (43 loc) · 1.46 KB
/
CSVfile.R
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#import and export csv(comma seperated values) file
getwd()
setwd("D:/study material/5TH SEM NOTES/DAR/RScripts")
getwd()
#syntax :
#write.csv(data,file = 'file-path',row.names = FALSE)
#data: The data frame or data you want to save.
#file: The file path where you want to save the CSV file.
#row.names: Setting it to FALSE ensures that row names (if any) are not included in the CSV file.
#read.csv("file-name")
dataframe <- data.frame(
id = c(1,2,3,4),
name = c("faisal","harsha","sujal","shreeya"),
dept = c("IT","CO","CIVIL","LATHER")
)
dataframe
write.csv(dataframe, file="D:/study material/5TH SEM NOTES/DAR/RScripts/first.csv",row.names = FALSE)
read.csv("D:/study material/5TH SEM NOTES/DAR/RScripts/first.csv")
#import another csv file and manipulate the data
second <- read.csv("second.csv")
second
str(second)
class(second)
second <- subset(second, Salary <= 60000)
second
list <- list(111,"John","Khan","CO","HR",70000,"2019-09-01")
#add row
second <-rbind(second , list)
second<- NULL
#add column
second <- subset(second , EmployeeID <107)
second
second$address <- list("Pune","Mumbai","Wadala","Bandra","Kharghar","Mulund")
second
#find the employee which has the maximum salary
emp <-subset(second,Salary ==max(Salary))
emp$FirstName
emp1 <- subset(second,Salary == min(Salary))
emp1$FirstName
second <- data.frame(second)
second
write.csv(dataframe,file="~/second.csv",row.names = FALSE)
getwd()