0% found this document useful (0 votes)
10 views3 pages

R Software Assignment 6 Solutions

The document provides solutions to an assignment on R software, detailing correct commands for various data manipulation tasks within dataframes. It includes commands for extracting row and column names, accessing specific variables, and filtering data based on conditions. Additionally, it covers reading CSV and Excel files into R, specifying the correct syntax for each operation.

Uploaded by

neeru572010
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

R Software Assignment 6 Solutions

The document provides solutions to an assignment on R software, detailing correct commands for various data manipulation tasks within dataframes. It includes commands for extracting row and column names, accessing specific variables, and filtering data based on conditions. Additionally, it covers reading CSV and Excel files into R, specifying the correct syntax for each operation.

Uploaded by

neeru572010
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MOOC Course ‐ Introduction to R Software

July 2017
Solution to Assignment 6
1. For a particular dataframe, the command rownames and colnames indicate the names
of rows and columns in the corresponding dataframe.

Hence option a is correct.

2. The commandstr(dataframe name) is the correct command to obtain the


dimension, name, and type of each variable in the corresponding dataframe.

Hence option c is correct.

3. The commanddata_frame_name$variable name is the correct command to


extract the variable from the corresponding dataframe.

Hence option d is correct.

4. The correct command to extract the information on the person whose name is XYZ
contained in the variable teacher from a dataframe master is
master["XYZ","teacher"].

Hence option b is correct.

5. The correct command to draw information on the painters who have used the "Colour"
coded 10 and are from "School" F from the data frame painters
issubset(painters,Colour=='10' & School == 'F')and the corresponding
outcome is

1
Composition Drawing Colour Expression School

Durer 8 10 10 8 F

Hence option c is correct.

6. The correct command to draw the information on those painters who have used the
"Drawings" as 10 and "Expression" is less than 13 is

subset(painters, Drawing=='10' & Expression <13)

and the corresponding output is

Composition Drawing Colour Expression School


Josepin 10 10 6 2 C
Veronese 15 10 16 3 D
Guercino 18 10 10 4 E
Durer 8 10 10 8 F
Diepenbeck 11 10 14 6 G

Hence option b is correct.

7. Note that Column 1 indicates "Composition" and the Column 4 indicates


"Expression". The correct command to draw the information and output on those
painters who have used the "Colour" coded as 6, "School" as F when information on
variables "Composition" and "Expression" is removed from the dataframe
painters is

subset(painters, School== "F" & Colour == "6", select=c(-1,-


4))and the corresponding outcome is

Drawing Colour School

Pourbus 15 6 F

Van Leyden 6 6 F

Hence option d is correct.

2
8. A comma separated value(csv) data file named as [Link] header can be correctly
read in R by the command

[Link]("[Link]",header=TRUE)

Hence option d is correct.

9. The sheet number 3 of the file [Link] having header can be correctly read in R by the
command

[Link]("[Link]",sheetIndex=3,header=TRUE).

Hence option a is correct.

10. The sheet named school of the file [Link] having header can be correctly read in R by
the command

[Link]("[Link]", sheetName= "school", header=TRUE) .

Hence option c is correct.

Common questions

Powered by AI

To extract information from a dataframe concerning painters who used a specific 'Drawing' value of 10 and an 'Expression' value less than 13, the command used in R is subset(painters, Drawing=='10' & Expression <13). This command filters data based on multiple conditions, providing a nuanced method of data extraction .

To access a specific person's information from a dataframe using their name in R, use the indexing method like master["XYZ","teacher"]. This extracts information where the person named XYZ is in the column 'teacher' .

Using row and column names, such as with the command rownames and colnames, provides a more intuitive and less error-prone method of accessing data compared to numerical indices. This is because names are self-descriptive, reducing confusion and enhancing code readability, while indices can lead to mistakes if not carefully tracked. Named access is exemplified in commands like master["XYZ","teacher"], which is clearer than master[1,2].

To load a CSV file with headers into R, use the command read.csv("abc.csv", header=TRUE). This command reads the CSV file while acknowledging that the first row contains column headers .

To remove specific columns when subsetting a dataframe in R, use the subset function with the select argument, specifying negative indices for columns to be removed. For example, to remove 'Composition' (Column 1) and 'Expression' (Column 4) while subsetting painters by 'School' and 'Colour', use subset(painters, School== "F" & Colour == "6", select=c(-1,-4)).

Using headers in R is crucial for appropriately naming columns, facilitating easier data manipulation and analysis. When reading CSV files, specify header information using read.csv("file.csv", header=TRUE), and for Excel sheets, use read.xlsx("file.xlsx", sheetIndex=n, header=TRUE). This ensures data is loaded with correct labels and structures, reducing errors and improving efficiency in subsequent data operations .

The command to extract variable values from a given dataframe in R is data_frame_name$variable_name. This allows for accessing specific vector within a dataframe .

To read data from the third sheet of an Excel file in R, the correct command is read.xlsx("abc.xlsx", sheetIndex=3, header=TRUE). This command specifies the file name, the sheet index to be read, and that the data has a header row .

Incorrectly specifying sheet indices when importing Excel files into R can lead to data from the wrong sheet being imported, resulting in erroneous analysis and conclusions. The command involves specifying the correct sheet index, like read.xlsx("abc.xlsx", sheetIndex=3, header=TRUE), which must match the intended sheet to avoid importing irrelevant or misleading data .

To filter rows based on multiple conditions involving string matches in R, use the subset function with combined logical conditions. For instance, to filter painters who used "Colour" coded 10 and are from "School" F, the command is subset(painters, Colour=='10' & School == 'F').

You might also like