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

R Assignment 3-1

The document contains instructions for 23 programming assignments in R. The assignments include writing programs to find even numbers in vectors, summarize and extract data from data frames, create and manipulate lists, sort vectors, implement algorithms like binary search trees and quicksort, define functions to manipulate data frames and vectors, and parse strings.

Uploaded by

Kapardhi kk
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)
68 views3 pages

R Assignment 3-1

The document contains instructions for 23 programming assignments in R. The assignments include writing programs to find even numbers in vectors, summarize and extract data from data frames, create and manipulate lists, sort vectors, implement algorithms like binary search trees and quicksort, define functions to manipulate data frames and vectors, and parse strings.

Uploaded by

Kapardhi kk
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
You are on page 1/ 3

Statistical Foundations of Computer Science (R)

Assignment 3
1. Find all even numbers from
a)a numeric vector
b)logical vector

2. Write a R program to
a) create the given dataframe and
b) get the statistical summary and nature of the data of a given data frame
c) to extract first two rows from a given data frame.
d) to add new row(s) to an existing data frame
e) to drop column(s) by name from a given data frame.

name score attempts qualify


Anastasia 12.5 1 yes
Dima 9.0 3 no
Katherine 16.5 2 yes
James 12.0 3 no
Emily 9.0 2 no
Michael 20.0 3 yes
Matthew 14.5 1 yes
Laura 13.5 1 no
Kevin 8.0 2 no
Jonas 19.0 1 yes

3. Write a R program to create a list of dataframes and access each of those dataframes from the
list.
4. Write a R program to create a list containing a vector, a matrix and a list and give names to
the elements in the list.
a) Access the first and second element of the list.
b) add element at the end of the list.
c) remove the second element.
d) update the last element.
5. Write a R program to get the length of the first two vectors of a given list.
6. Write a R program to concatenate two given factor in a single factor.
7. Write a R program to find the levels of factor of a given vector.
8. Implement Binary search tree using R programming.
9. Write a R program to implement quick sort using recursion.
10. Print the following pattern using R programming.
1
22
333
4444
55555

11. Write a R program to check whether the given number is armstrong number or not.
12. Given a data frame and a vector, create a function that will add a the vector (if the vector
length match with the rows number of the data frame) as a new variable to the data frame.

13. Consider a data frame df:

Id=c(1:10)
Age=c(14,12,15,10,23,21,41,56,78,12)
Sex=c('F','M','M','F','M','F','M','M','F','M')
Code=letters[1:10]
df=data.frame(Id,Age,Sex,Code)

14.Create a function that, given a data frame and two indexes, exchanges two values of the
Code variable with each other.
For example, if the index is 1 and 3, you assign:

df[1,'Code']=df[3,'Code']
df[3,'Code']=df[1,'Code']

15. Consider two variables x,y and a data frame df:

x,y integer

A=c(1:10)
B=seq(100,10,-10)
H=seq(-200,-50,along.with=B)
df=data.frame(A,B,H)

Create a function that given a data frame df calculate a new variable ‘SUM_x_y'(If x=2 and
y=3, then the new variable will be ‘SUM_2_3’,
if x=4 and y=10, then the new variable will be ‘SUM_4_10’),such that for each row ‘i’ is
equal to:

sum(x*df[1:i,1])+sum(y*df[1:i,2])

16. Create a function that given a numeric vector, sort this in ascending order and duplicate it
by two.

17. Create a function that given a numeric vector X returns the digits 0 to 9 that are not in X.
If X=0 2 4 8
the function return 1 3 5 6 7 9

18.Create a function that given two strings (one word each), check if one is an anagram of
another.

19. Create a function that given one word, return the position of word’s letters
on letters vector.
For example, if the word is ‘abc’, the function will return 1 2 3.
20. Create a function that given a string

ST='NAME: Maria /COUNTRY:uruguay /EMAIL: [email protected]'

return a matrix

[,1] [,2]
[1,] "NAME" " Maria "
[2,] "COUNTRY" "uruguay "
[3,] "EMAIL" " [email protected]"

21. Consider a vector:

ST=c('NAME:Maria /COUNTRY:uruguay
/EMAIL:[email protected]','NAME:Paul/COUNTRY:UK
/EMAIL:[email protected]',

'NAME:Jhon /COUNTRY:USA /EMAIL:[email protected]','NAME:Carlos


/COUNTRY:Spain /EMAIL:[email protected]')

Create a function that given a vector string ST return a matrix:

[,1] [,2] [,3] [,4] [,5]

[1,] "NAME" "Maria " "Paul" "Jhon " "Carlos "

[2,] "COUNTRY" "uruguay " "UK " "USA " "Spain "

[3,] "EMAIL" "[email protected]" "[email protected]" "[email protected]"


"[email protected]"

You might also like