August 30, 2018

Sreekanth B

Cognizant R Programming Recently Asked Interview Questions Answers

How to create the S3 class?

We can show how to define a function that will create and return an object of a given class. A list is been created with the relevant members, the list’s class is set, and a copy of the list is been returned.

What is S4 Generic?

The function setGeneric is the call to make a new generic function.

> setGeneric("BMI", function(object) standardGeneric("BMI"))
> setMethod("BMI", "personS4", function(object) {
+ object@weight/object@height^2
+ })
> BMI(jimS4)

How to request an input from the user through keyboard and monitor?

In R, there are a series of functions that can be used to request an input from the user,
including readline(), cat(), and scan(). But, I find the readline() function to be the optimal function for this task.
Cognizant R Programming Recently Asked Interview Questions Answers
Cognizant R Programming Recently Asked Interview Questions Answers

How to read data from the keyboard?

To read the data from keyboard we use three different functions:


How many ways are there to read and write files?

There are three ways to read and write files respectively:

Reading a data or matrix from a file
Reading a single File One Line at a Time
Writing a Table to a File

Explain how to read data or a matrix from a file?

a) Usually we use function read.table() to read data. The default value of a header is ‘FALSE’ and hence when we do not have a header, we need not say such. , R factors are also called as character strings. For turning this “feature” off, you can include the argument in your call to read.table().
b) When you have a spreadsheet export file, i.e. having a type.csv where the fields are divided by commas in place of spaces, use read.csv() in place of read.table(). To read spreadsheet files we can use read.xls.
c) When you read in a matrix using read.table(), the resultant object will become a data frame, even when all the entries got to be numeric. A case exists which may followup call towards as.matrix() in a matrix. We need to read it into a matrix form like this
> x <- matrix(scan(“x”),nrow=5,byrow=T)

What are Sockets in R?

Sockets provide two networked machines with a bidirectional communication channel. Servers are accessed via socket addresses, a combination of the server&#39;s IP address and a port number. We use the port as a connection point on the server, like USB or Firewire ports, with each port serving a specific purpose.

For example:

Web pages are served on port 80 (HTTP), emails are sent via port 25 (SMTP).


make.socket(host = "localhost", port, fail = TRUE, server = FALSE)

host name of remote host
port port to connect to/listen on
fail failure to connect is an error?
Server a server socket?

What is protocol?

A protocol is a set of rules and procedures. It means what format to use, what data mean, when should data be sent. When two computers exchange data, they can understand each other if both follow specific format and rules in a protocol. It is a set of rules and procedures and computers. It is been used to communicate.

What does TCP/IP work?

TCP/IP protocols map to a four-layer conceptual model known as the DARPA model. The four layers of the DARPA model are Application, Transport, Internet, and Network Interface.

Explain TCP/IP applications, services and protocols?

Bootstrap protocol – Bootstrap Protocol (BOOTP) provides a dynamic method for associating workstations with servers. It is a method which also provides a dynamic method for assigning workstation Internet Protocol (IP) addresses and initial program load (IPL) sources.
Domain name system – We use Domain Name System (DNS) to manage host names and their associated Internet Protocol (IP).
Email – Use this information to plan for, configure, use, manage, and troubleshoot e-mail on your system.
Open shortest path first search – IBM I support includes the Open Shortest Path First (OSPF) protocol. OSPF is a link-state, hierarchical Interior Gateway Protocol (IGP) for network routing.
RouteD – The Route Daemon (RouteD) provides support for the Routing Information Protocol (RIP) on the IBM platform.
Simple network time protocol – It is a time-maintenance application that we can use to synchronize hardware in a network.

What is TCP/IP variable SMC-R storage allocations?

Each more RMB that is been allocated for a particular SMC-R link group can accommodate 4 – 32
more TCP connections, depending on the RCVBFRSIZE value of the TCP connections.
More staging buffers are allocated as the volume of application data that is been sent increases.
RMBs, staging buffers, and RDMA receive and send elements are all eligible to be deallocated if the volume of application traffic decreases.

What is debugging in R?

A grammatically correct program may give us incorrect results due to logic errors. In case such errors (i.e. bugs) occur, we need to find out why and where they occur so that you can fix them. The procedure to identify and fix bugs is called “debugging”.

What are tools for debugging in R?

There are five toos present for debugging in R respectively:


What are connections In R?

Functions to Manipulate Connections (Files, URLs, …). Functions to create, open and close connections.
For example: “generalized files”, such as compressed files, URLs, pipes, etc.

file, connection

Explain an Extended example of connections?

Extended Example: Reading PUMS sample files
These files contain records for a sample of housing units with information on the characteristics of each unit.

 Why use PUMS?

PUMS files provide greater accessibility to inexpensive data for research projects. Thus it is beneficial for students as they are looking for greater accessibility to inexpensive data. Social scientists often use the PUMS for regression analysis and modeling applications.

How can I access PUMS?

Statistical software is the tool used to work with PUMS files.

Which function is used to write files?

We use write.csv() to write files.

Explain how to write files?

We use write.csv() to write file. By default, write.csv() includes row names.

# A sample data frame
data <- read.table(header=TRUE, text='
subject sex size
1 M 7
2 F NA
3 F 9
4 M 11
# Write to a file, suppress row names
write.csv(data, "data.csv", row.names=FALSE)
# Same, except that instead of "NA", output blank cells
write.csv(data, "data.csv", row.names=FALSE, na=" ")
# Use tabs, suppress row names and column names
write.table(data, "data.csv", sep="\t", row.names=FALSE, col.names=FALSE)

What are fundamental principles of debugging?

Programmers often find that they spend more time debugging a program than actually writing it. Good debugging skills are invaluable. There are four basic principles of debugging:

The essence of debugging: The principle of confirmation
Start Small
Debug in a Modular, Top-Down Manner

What is a Graphic device?

A graphics device is something where we can make a plot to appear. When we make a plot in R, it has to be “sent” to a specific.

Window on your computer (screen device) 2. PDF file (file device)
PNG or JPEG file (file device)
Scalable vector graphics (SVG) file (file device)
The most common place for a plot to be “sent” is the screen device.

A Mac, the screen device is launched with the quartz()
Windows, the screen device is launched with windows()
Unix/Linux, the screen device is launched with x11()

Explain R graphics devices?

The following devices are currently available:

PDF – Write PDF graphics commands to file.
xfig – Device for XFIG graphics file format.
pictex – Writes TeX/PicTeX graphics commands to a file (of historical interest only).
postscript – Writes PostScript graphics commands to a file.
bitmap – bitmap pseudo-device via Ghostscript (if available).
The following devices will be functional if R was compiled to use them:

png – PNG bitmap device
jpeg – JPEG bitmap device
bmp – BMP bitmap device
tiff – TIFF bitmap device
X11 – The graphics device for the X11 windowing system.
svg – SVG device based on Cairo graphics.
cario.pdf – cairo_ps PDF and PostScript devices based on Cairo graphics.
quartz – The graphics device for the macOS native Quartz 2d graphics system.

Explain how to save graphs in R?

R runs on so many different operating systems. It supports so many different graphics formats.

JPEG – jpeg is been used anywhere but doesn’t resize
PNG – png is been used anywhere but doesn’t resize
WMF – win.metafile Windows only; best choice with Word; easily resizable
PDF – pdf pdflatex; easily resizable
Postscript – Postscript latex and Open Office; easily resizable.

Subscribe to get more Posts :