Featured Post

Python Set Operations Explained: From Theory to Real-Time Applications

Image
A  set  in Python is an unordered collection of unique elements. It is useful when storing distinct values and performing operations like union, intersection, or difference. Real-Time Example: Removing Duplicate Customer Emails in a Marketing Campaign Imagine you are working on an email marketing campaign for your company. You have a list of customer emails, but some are duplicated. Using a set , you can remove duplicates efficiently before sending emails. Code Example: # List of customer emails (some duplicates) customer_emails = [ "alice@example.com" , "bob@example.com" , "charlie@example.com" , "alice@example.com" , "david@example.com" , "bob@example.com" ] # Convert list to a set to remove duplicates unique_emails = set (customer_emails) # Convert back to a list (if needed) unique_email_list = list (unique_emails) # Print the unique emails print ( "Unique customer emails:" , unique_email_list) Ou...

How to Execute Commands in R Language

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:
#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 then press enter before typing 2, R knows that 1+ by itself doesn’t make any sense, so prompts for you to continue the line with a + sign. At this point, you could continue the line by pressing 2 then enter. This commonly occurs if you forget to close parentheses or brackets. 
  • If you keep pressing enter and keep seeing a + sign rather than the regular > prompt that allows you to type new code, and if you can’t figure out why, often the easiest option is to simply press ESC, which will get you back to the normal > prompt and allow you to enter a new line of code. 
Capitalization and punctuation need to be exact in R, but spacing doesn’t matter. If you get errors when entering the code, you may want to check for these common mistakes:
  1. Did you start your line of code with a fresh prompt (>)? If not, press ESC.
  2. Are your capitalization and punctuation correct?
  3. Are all your parentheses and brackets closed? For every forward (, {, or [, make sure there is a corresponding backward), }, or ]

R Script

Rather than typing a command in a console, you can create a script using a group of commands.  Code (commands) can be typed here, and then entered into the console in one of three ways:
  1. Copy the code in the R script and paste in the console
  2. Right-click on a line or highlighted group of lines and choose “Run line or selection”
  3. Place your cursor on a line or highlight a group of lines and press CTRL+R. 
The Scripts in R-Language are powerful and re-usable.

Comments

Popular posts from this blog

SQL Query: 3 Methods for Calculating Cumulative SUM

Big Data: Top Cloud Computing Interview Questions (1 of 4)

5 SQL Queries That Popularly Used in Data Analysis