Friday, January 20, 2023

Read Write File CSV Pada Programming-R

 


1. Buat file:   read.csv

id,name,salary,start_date,dept  

1,Shubham,613.3,2012-01-01,IT  

2,Arpita,525.2,2013-09-23,Operations  

3,Vaishali,63,2014-11-15,IT  

4,Nishka,749,2014-05-11,HR  

5,Gunjan,863.25,2015-03-27,Finance  

6,Sumit,588,2013-05-21,IT  

7,Anisha,932.8,2013-07-30,Operations  

8,Akash,712.5,2014-06-17,Financ  


2. Read file csv

2.1. Baca seluruh file 

data <- read.csv("read.csv")  

print(data)



2.2. membaca jumlah kolum & baris:

csv_data<- read.csv("read.csv")  

print(is.data.frame(csv_data))  

print(ncol(csv_data))  

print(nrow(csv_data)) 



2.3. membaca nilai maksimal :

# Creating a data frame.  

csv_data<- read.csv("read.csv")  

# Getting the maximum salary from data frame.  

max_sal<- max(csv_data$salary)  

print(max_sal)   


2.4. membaca dengan kondisi salary maksimal:

# Creating a data frame.  

csv_data<- read.csv("read.csv")  

# Getting the maximum salary from data frame.  

max_sal<- max(csv_data$salary)  

print(max_sal)  

#Getting the detais of the pweson who have maximum salary  

details <- subset(csv_data,salary==max(salary))  

print(details)   


2.5. membaca field dept = IT

# Creating a data frame.  

csv_data<- read.csv("read.csv")  

#Getting the detais of all the pweson who are working in IT department  

details <- subset(csv_data,dept=="IT")  

print(details)  



2.6.  membaca kondisi field dept = IT dan salary > 600

# Creating a data frame.  

csv_data<- read.csv("read.csv")  

#Getting the detais of all the pweson who are working in IT department  

details <- subset(csv_data,dept=="IT"&salary>600)  

print(details) 


2.7.  kondisi dengan field tanggal

# Creating a data frame.  

csv_data<- read.csv("read.csv")  

#Getting details of those peoples who joined on or after 2014  

details <- subset(csv_data,as.Date(start_date)>as.Date("2014-11-01"))  

print(details)




3. Write File CSV

csv_data<- read.csv("read.csv")  

#Getting details of those peoples who joined on or after 2014  

details <- subset(csv_data,as.Date(start_date)>as.Date("2014-06-01"))  

# Writing filtered data into a new file.  

write.csv(details,"output.csv")  

new_details<- read.csv("output.csv")  

print(new_details)  


Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...