Cookies help us display personalized product recommendations and ensure you have great shopping experience.

By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
SmartData CollectiveSmartData Collective
  • Analytics
    AnalyticsShow More
    data analytics for pharmacy trends
    How Data Analytics Is Tracking Trends in the Pharmacy Industry
    5 Min Read
    car expense data analytics
    Data Analytics for Smarter Vehicle Expense Management
    10 Min Read
    image fx (60)
    Data Analytics Driving the Modern E-commerce Warehouse
    13 Min Read
    big data analytics in transporation
    Turning Data Into Decisions: How Analytics Improves Transportation Strategy
    3 Min Read
    sales and data analytics
    How Data Analytics Improves Lead Management and Sales Results
    9 Min Read
  • Big Data
  • BI
  • Exclusive
  • IT
  • Marketing
  • Software
Search
© 2008-25 SmartData Collective. All Rights Reserved.
Reading: R –Refcards and Basic I/O Operations
Share
Notification
Font ResizerAa
SmartData CollectiveSmartData Collective
Font ResizerAa
Search
  • About
  • Help
  • Privacy
Follow US
© 2008-23 SmartData Collective. All Rights Reserved.
SmartData Collective > Big Data > Data Mining > R –Refcards and Basic I/O Operations
Data Mining

R –Refcards and Basic I/O Operations

Editor SDC
Editor SDC
4 Min Read
SHARE

While working with a large number of files for data processing, I used the following R commands for data processing. Given that everyone needs to split as well merge and append data – I am just giving some code on splitting data based on parameters , and appending data as well as merging data.
 
Splitting Data […]

While working with a large number of files for data processing, I used the following R commands for data processing. Given that everyone needs to split as well merge and append data – I am just giving some code on splitting data based on parameters , and appending data as well as merging data.

 

More Read

Delivering Data Warehousing and BI Projects using Agile
Predictive Analytics: 8 Things to Keep in Mind (Part 7)
Top 10 analytics mistakes
Why Does Data Decay so Fast?
SAS , R and NYT – The Sequel

Splitting Data Based on a Parameter.

The following divides the data into subsets which contain either Male or anything else in different datasets.

Input and Subset

Note the read.table command assigns the dataset name X in R environment from the file reference (path denoted by ….)

x <- read.table(....)
rowIndx <- grep("Male", x$col)
write.table(x[rowIndx,], file="match")
write.table(x[-rowIndx,], file="nomatch")

Suppose we need to divide the dataset into multiple data sets.


X17 <- subset(X, REGION == 17)

This is prefered to the technique -
attach(X)
X17 = X[REGION == 17,]

 

Output

For putting the files back to the Windows environment you can use-

write.table(x,file="",row.names=TRUE,col.names=TRUE,sep=" ")

Append

Lets say you have a large number of data files ( say csv files )

that you need to append (assuming the files are in same syrycture)

after performing basic operations on them.

 

>setwd("C:\\Documents and Settings\\admin\\My Documents\\Data")

Note this changes the working folder to folder you want it to be,

note the double slashes which are needed to define the path

>list.files(path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE,

+     recursive = FALSE, ignore.case = FALSE)

The R output would be something like below

 

 [1] "cal1.csv"                                     "cal2.csv"                                           

[3] "cal3.csv"                                     "cal4.csv"                                           

[5] "cal5.csv"                                     "cal6.csv"                                           

[7] "cal7.csv"                                     "cal8.csv"

 

Now you can use the file.append command for succesively appending the second file

to the first file.

If writing a lot of similar code is a tedium use the & (concatenate) function

in excel to create the code.Note the Formula Bar (B7=A7&C7&D7&E7)

Excel is useful because it is good in click and drag repetitive text and

concatenation is easily done.

image

 

The output would be something like

>file.append("cal1.csv","cal2.csv")
[1] TRUE
>file.append("cal1.csv","cal3.csv")
[1] TRUE
>file.append("cal1.csv","cal4.csv")
[1] TRUE
>file.append("cal1.csv","cal5.csv")
[1] TRUE
>file.append("cal1.csv","cal6.csv")
[1] TRUE
>file.append("cal1.csv","cal7.csv")
[1] TRUE
>file.append("cal1.csv","cal8.csv")
[1] TRUE

 

Note all data here gets appended to filecal1.csv

This should be a good starting point for you to trying out R.

For a Reference Sheet, here is an excellent reference sheet from Tom Short,

and it is aptly called the Short Refcard

(http://cran.r-project.org/doc/contrib/Short-refcard.pdf)

Note- Experienced analytics people are best served by

www.rforsasandspssusers.com

Anyways MeRRy ChRistmas !

 

Short Refcard

Publish at Scribd or explore others: Mathematics Science R

Share This Article
Facebook Pinterest LinkedIn
Share

Follow us on Facebook

Latest News

dedicated servers for ai businesses
5 Reasons AI-Driven Business Need Dedicated Servers
Artificial Intelligence Exclusive News
data analytics for pharmacy trends
How Data Analytics Is Tracking Trends in the Pharmacy Industry
Analytics Big Data Exclusive
ai call centers
Using Generative AI Call Center Solutions to Improve Agent Productivity
Artificial Intelligence Exclusive
warehousing in the age of big data
Top Challenges Of Product Warehousing In The Age Of Big Data
Big Data Exclusive

Stay Connected

1.2kFollowersLike
33.7kFollowersFollow
222FollowersPin

You Might also Like

Hadoop in retail
AnalyticsBig DataCloud ComputingData MiningData QualityData WarehousingHadoopHardwareITMapReduceMarketingMarketing AutomationOpen SourcePredictive AnalyticsSentiment AnalyticsSocial DataSocial Media AnalyticsSoftwareSQLText AnalyticsUnstructured DataWeb AnalyticsWorkforce AnalyticsWorkforce Data

5 Big Data Hadoop Use Cases for Retail

5 Min Read

In Defense of Data Mining Ethics

5 Min Read

PASW 13 :The preview

3 Min Read

Seven Misconceptions about Data Quality

11 Min Read

SmartData Collective is one of the largest & trusted community covering technical content about Big Data, BI, Cloud, Analytics, Artificial Intelligence, IoT & more.

data-driven web design
5 Great Tips for Using Data Analytics for Website UX
Big Data
AI and chatbots
Chatbots and SEO: How Can Chatbots Improve Your SEO Ranking?
Artificial Intelligence Chatbots Exclusive

Quick Link

  • About
  • Contact
  • Privacy
Follow US
© 2008-25 SmartData Collective. All Rights Reserved.
Go to mobile version
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?