Posts

Showing posts with the label R Language

Featured Post

15 Python Tips : How to Write Code Effectively

Image
 Here are some Python tips to keep in mind that will help you write clean, efficient, and bug-free code.     Python Tips for Effective Coding 1. Code Readability and PEP 8  Always aim for clean and readable code by following PEP 8 guidelines.  Use meaningful variable names, avoid excessively long lines (stick to 79 characters), and organize imports properly. 2. Use List Comprehensions List comprehensions are concise and often faster than regular for-loops. Example: squares = [x**2 for x in range(10)] instead of creating an empty list and appending each square value. 3. Take Advantage of Python’s Built-in Libraries  Libraries like itertools, collections, math, and datetime provide powerful functions and data structures that can simplify your code.   For example, collections.Counter can quickly count elements in a list, and itertools.chain can flatten nested lists. 4. Use enumerate Instead of Range     When you need both the index ...

R Language basics for Beginners to Apply in Analytics

Image
In the early days, a key feature of R was that its syntax is very similar to S, making it easy for S-PLUS users to switch over. While the R’s syntax is nearly identical to that of S’s, R’s semantics, while superficially similar to S, are quite different. Steps to learn R Language In fact, R is technically much closer to the Scheme language than it is to the original S language when it comes to how R works under the hood. Today R runs on almost any standard computing platform and operating system. Its open-source nature means that anyone is free to adapt the software to whatever platform they choose. #R language basics Indeed, R has been reported to be running on modern tablets, phones, PDAs, and game consoles. One nice feature that R shares with many popular open-source projects is frequent releases. These days there is a major annual release, typically in October, where major new features are incorporated and released to the public. Throughout the year, smaller-scale bugfix release...

R objects useful command to delete them

Image
R-Commands The entities that R creates and manipulates are known as objects. These may be variables, arrays of numbers, character strings, functions, or more general structures built from such components. During an R session, objects are created and stored by name. This post tells you how to delete them. The R command > objects() (alternatively, ls()) can be used to display the names of (most of) the objects which are currently stored within R. The collection of objects currently stored is called the workspace. The data visualization in R Language with GGplot a good idea to start. To remove objects the function rm is available: > rm(x, y, z, ink, junk, temp, foo, bar) All objects created during an R session can be stored permanently in a file for use in future  R sessions. At the end of each R session you are given the opportunity to save all the currently available objects. If you indicate that you want to do this, the objects are written to a file calle...

R Language: How to Use 'Help' Command

Image
Help command in R-Language R has an inbuilt help facility similar to the man facility of UNIX. To get more information on any specific named function, for example solve, the command is > help(solve) An alternative is > ?solve For a feature specified by special characters, the argument must be enclosed in double or single quotes, making it a “character string”: This is also necessary for a few words with syntactic meaning including if, for and function. > help("[[") Either form of quote mark may be used to escape the other, as in the string "It’s important". Our convention is to use double quote marks for preference. On most R installations help is available in HTML format by running > help.start() which will launch a Web browser that allows the help pages to be browsed with hyperlinks. On UNIX, subsequent help requests are sent to the HTML-based help system. The ‘Search Engine and Keywords’ link in the page loaded by help.start() is par...

R Language: Data types and structures

Image
To make the best of the R language, you'll need a strong understanding of the basic data types and data structures and how to operate on those. Very Important to understand because these are the things you will manipulate on a day-to-day basis in R. Everything in R is an object. The basic data types  logical (e.g., TRUE, FALSE) integer (e.g,, 2L, as.integer(3)) numeric (real or decimal) (e.g, 2, 2.0, pi) complex (e.g, 1 + 0i, 1 + 4i) character (e.g, "a", "swc") The basic data structures in R vector list matrix data frame factors tables Vector in R A vector is the most common and basic data structure in R and is pretty much the workhorse of R.  Vectors can be of two types: atomic vectors lists

R language five useful real functions

Image
In Data Science R language plays a crucial role. In the R language, there are five top functions present. These functions I have explained in this post. 1. Storing Values Stores a value to variable. The value can be same or mixed data type. It is available /* */ to give comments for your scripts inside Char, Double, Boolean and Decimal are more frequently used data types 2. Reading data from files Large data objects will usually be read as values from external files rather than entered during an R session at the keyboard.  R input facilities are simple and their requirements are fairly strict and even rather inflexible. There is a clear presumption by the designers of R that you will be able to modify your input files using other tools, such as file editors or Perl1 to fit in with the requirements of R. Generally this is very simple. If variables are to be held mainly in data frames, as we strongly suggest they should be, an entire data frame can be read direct...

How to write R Script in simple way

Image
A script is a good way to keep track of what you're doing. If you have a long analysis, and you want to be able to recreate it later, a good idea is to type it into a script. If you're working in the Windows R GUI (also in the Mac R GUI), there is even a built-in script editor. Photo credit: Srini To get to it, pull down the File menu and choose New Script (New Document on a Mac). A window will open in which you can type your script. R Script is a series of commands that you can execute at one time and you can save a lot of time. the script is just a plain text file with R commands in it. How to create an R Script You can prepare a script in any text editor, such as vim, TextWrangler, or Notepad. You can also prepare a script in a word processor, like Word, Writer, TextEdit, or WordPad, PROVIDED you save the script in plain text (ASCII) format. This should (!) append a ".txt" file extension to the file. Drop the script into your working directory, and...

How to Execute Commands in R Language

Image
The next step after installing R is how to run commands. You can run directly by entering commands. The other way is you need to write an R script, that contains all the series of commands. The benefit of the script is you can save your commands, it saves your time. Second, as a script, you can run it whenever you need. #How to Run-commands in R: Executing Commands in R Commands can be entered directly into the R console (the window that opens when you start R), following the red > prompt, and sent to the computer by pressing enter. For example, typing 1 + 2 and pressing enter will output the result 3: > 1+2 [1] 3 Your entered code always follows the > prompt, and output always follows a number in square brackets. Each command should take its own line of code, or else a line of code should be continued with { }  It is possible to press enter before the line of code is completed, and often R will recognize this. For example, if you were to type 1 + but the...

Here is a Quick Way to Know Current Working Directory in R

If R is not finding the file you are trying to read then it may be looking in the wrong folder/directory. If you are using the graphical interface you can change the working directory from the file menu. List of Files and Current Working Directory Related: JOBS in R Language If you are not sure what files are in the current working directory you can use the dir() command to list the files and the getwd() command to determine the current working directory: > dir () [1] "fixedWidth.dat" "simple.csv" "trees91.csv" "trees91.wk1" [5] "w1.dat" > getwd () [1] "/home/black/write/class/stat/stat383-13F/dat"

R Language Tutorial for Mainframe Programmers

Why R? It's free, open source, powerful and highly extensible. "You have a lot of prepackaged stuff that's already available, so you're standing on the shoulders of giants," Google's chief economist told The New York Times back in 2009. Free Resources on R Language Part 1: Introduction Part 2: Getting your data into R Part 3: Easy ways to do basic data analysis Part 4: Painless data visualization Part 5: Syntax quirks you'll want to know Part 6: Useful resources Details of R Language Because it's a programmable environment that uses command-line scripting, you can store a series of complex data-analysis steps in R. That lets you re-use your analysis work on similar data more easily than if you were using a point-and-click interface, notes Hadley Wickham, author of several popular R packages and chief scientist with RStudio. That also makes it easier for others to validate research results and check your work for errors -- an issue that...