diff --git a/builtin functions.R b/builtin functions.R new file mode 100644 index 0000000..61dbf1f --- /dev/null +++ b/builtin functions.R @@ -0,0 +1,39 @@ + +#builtin function +a<-45.6 +print(floor(a)) +print(ceiling(a)) +print(abs) + +x<-c(26.36,25.3,26.96) +print(trunc(x)) + +y<-45 +print(sqrt(y)) +print(exp(y)) +print(sin(y)) +print(log(y)) + + +f<-c("123456789") +substr(a,2,7) +#isame tumhe 3 cheeje deni padati hai pahla jisame pata karna ho substring then start and stop point + + +u<-c("abd","anbvhdy","abcde") +pat<-"^abd" +print(grep(u,pat)) + + + +g<-15 +h<-15 +print(sum(g+h)) + + +k<-c(238,36,96,85,454,58,91,65) +print(max(k)) +print(min(k)) + + + diff --git a/code.R b/code.R new file mode 100644 index 0000000..03d78ac --- /dev/null +++ b/code.R @@ -0,0 +1,8 @@ +example_function=function(x,y) + {c(x+1,y+10)} +example_function(5,6) + + +log(2) +tan(5) +exp(12) diff --git a/dataframe.R b/dataframe.R new file mode 100644 index 0000000..016411c --- /dev/null +++ b/dataframe.R @@ -0,0 +1,27 @@ +hspA=list(gene="hsp1a",amino.acids=650,nucleotideds=550) +print(hspA) + + +#lets pull out just the gene +hspA$gene +#lets pull out the amino acids +hspA$amino.acids +#lets pull out the nucleotides +hspA$nucleotideds + +#let's ceate three list and combine them into data frame + +gene=c("hspa1","hspa2","hspa3","hspa4","hspa5","hspa6") +amino.acids=c(125,365,254,654,158,369) +nucleotides=c(2400,2600,2500,2500,3600,2900) + +hsp=data.frame(gene,amino.acids,nucleotides) +print(hsp) +#just pull out the gene from dataframe +hsp$gene +#let's pull out the nucleotides from data frame +hsp$nucleotides +#let's search for specific amino acids +hsp$amino.acids[hsp$gene=="hspa6"] + + diff --git a/datatype convert.R b/datatype convert.R new file mode 100644 index 0000000..7be0bae --- /dev/null +++ b/datatype convert.R @@ -0,0 +1,76 @@ + +#logical datatype +log1<-as.logical(0) +log1 + +log2<-as.logical(26L) +log2 + +log3<-as.logical("2654156bjgu") +log3 + + +log4<-as.logical(23261.31653416) +log4 + +# logic datatypes me fralse ke liye zero baki usake alawa koi bhi value aaye true +#non zero value==true +#zero value ==false + + + +#numeric + +num1<-as.numeric(TRUE) +num1 + +num2<-as.numeric(FALSE) +num2 + +num3<-as.numeric("1542615") +num3 + +num4<-as.numeric(26L) +num4 + +num5<-as.numeric(25+6i) +num5 + +num6<-as.numeric(36523.323654) +num6 + + +#COMPLEX + +comp1<-as.complex(25L) +comp1 + +comp2<-as.complex(2653.365254) +comp2 + +comp3<-as.complex("26444") +comp3 + +comp4<-as.complex(455465464L) +comp4 + +comp5<-as.complex(TRUE) +comp5 + + +#INTEGER + +int1<-as.integer(TRUE) +int1 + +int2<-as.integer(2635.3265) +int2 + +int3<-as.integer("1542") +int3 + +int4<-as.integer(2422242) +int4 + +int5<-as.integer(26+5i) +int5 \ No newline at end of file diff --git a/datatypes.R b/datatypes.R new file mode 100644 index 0000000..b69f20f --- /dev/null +++ b/datatypes.R @@ -0,0 +1,41 @@ +#datatypes in r + +#logical,integer,raw,complex,character,numeric + +#numeric--->15,26.265,11.154,1542 + +#complex=45+2i + +#integer=125L + +#caharacter="faad dunga","2.365","hello","vibhanshu singh gaharwar" + +#logical=TRUE,FALSE + + +num<-15 +class(num) +typeof(num) + + +intl<-15 +class(intl) + +intl<-as.integer(intl) +class(intl) + +int2<-15L +class(int2) +typeof(int2) + +int3<-16L +class(int3) + +comp<-15-12i +class(comp) + +logi<-TRUE +class(logi) + +char<-"vibhu singh gaharwar" +class(char) diff --git a/first class.R b/first class.R new file mode 100644 index 0000000..4eb92c7 --- /dev/null +++ b/first class.R @@ -0,0 +1,7 @@ +days=c("monday","tuesday","wednesday","thursday","friday","saturday","sunday") +days[5] +days[1:6] +days[1:7] +weakdays=days[(4:6)] +print(weakdays) + diff --git a/for and repeat.R b/for and repeat.R new file mode 100644 index 0000000..4fabe36 --- /dev/null +++ b/for and repeat.R @@ -0,0 +1,37 @@ +#for loop + +for (val in 1:10) { + print(paste("number:,",val)) + # paste for concatanation of string + +} + + +f<-c("mango","banana","apple","pomgranate","orange","watermalon") +for (i in f) { + print(i) + print(f) + +} + + + + +#repeat +# repeat -------------------> loop without any condition + +a<-c("atul","singh","gaharwar","vibhu","singh","dadu") +x<-2 +repeat{ + x<-x+1 + if(x>5){ + break + } + print(a) +} + + + + + + diff --git a/functions.R b/functions.R new file mode 100644 index 0000000..0b01954 --- /dev/null +++ b/functions.R @@ -0,0 +1,30 @@ + +#function +examplefunction=function(x,y) +{c(x+10,y+36)} +examplefunction(36,45) + + + + + +new_function<-function(x,y,z){ + res<-x+y+z +print(res) + +} +new_function(x=45,y=36,z=14) + + + + + + + +square_function=function(){ + for (i in 1:5){ + print(i^2) + } + +} +square_function() \ No newline at end of file diff --git a/if else.R b/if else.R new file mode 100644 index 0000000..1368494 --- /dev/null +++ b/if else.R @@ -0,0 +1,41 @@ +x<-45 +if(x==45){ + print("x is equal to 45") +}else{ + print("x is not equal to 45") +} + + +a<-26 +b<-15 +if(a75){ + print("pass with first class") +}else if(marks>65){ + print("pass with second class ") +}else if(marks>45){ + print("pass with third class") +}else{ + print("fail") +} + + + + +y<-c("vibhu","singh","gaharwar"," is", "dsciplined","boy") +if("vibhu" %in% y){ + print("vibhu is found in vector ") +}else{ + print("vibhu is not found in vector ") +} + + + diff --git a/input from user.R b/input from user.R new file mode 100644 index 0000000..659318d --- /dev/null +++ b/input from user.R @@ -0,0 +1,6 @@ +name<-readline(prompt = "enter your name:") +age<-readline(prompt = "enter your age:") + +print(paste("hello my name is ",name,"and my age is",age)) +paste("vibhu","ram","2320") +paste0("vibhu","ram","2365") \ No newline at end of file diff --git a/introduction to R.R b/introduction to R.R new file mode 100644 index 0000000..5a6d368 --- /dev/null +++ b/introduction to R.R @@ -0,0 +1,6 @@ +#welcome to r programming language +sum1<-45+36 +sum1 +sessionInfo() +x<-1:10 +plot(x) diff --git a/list.R b/list.R new file mode 100644 index 0000000..65c1960 --- /dev/null +++ b/list.R @@ -0,0 +1,51 @@ +# vector me ek hi tarah ke datatypes ko bas rakh sakte h + +#list----using list() function + +vec<-c(8,9,4,7,6) +char_vect<-c("ram","shayam","mohan","sohan","rohan") +logic_vec<-c(TRUE,FALSE,TRUE,FALSE,TRUE) +list1<-list(vec,char_vect,logic_vec) +list1 + +list2<-list("ram","sohan",c(1,2,3,4,5),TRUE,FALSE,25L,26.35) +list2 + + +# naming of list +list3<-list(c("ram","syam","mohan"),c(15,36,96),c("btech","ba","b.sc")) +list3 +names(list3)<-c("students","marks","courses") +list3 +# accesing the list +print(list3[3]) +print(list3["marks"]) +print(list3$marks) + +#unlist----->convert list into vector + +list3<-list(5:9) +list3 +list4<-list(14:19) +list4 + + + + +v1<-unlist(list3) +v2<-unlist(list4) +res<-v1+v2 +res + +class(v1) +typeof(v1) +list3<-list(5:9) +list4<-list(14:18) +mer<-list(list3,list4) +mer + + + + + + diff --git a/next and break.R b/next and break.R new file mode 100644 index 0000000..18cf1f3 --- /dev/null +++ b/next and break.R @@ -0,0 +1,23 @@ +# next-------> jo abhi satement ka execution chal raha hai usame skip the current iteration +#but not terminate loop until condition will false + +a<-1:10; +for (val in a) { + + if (val==5){ + next + } + print(val) + +} + + +#break-------> to terminate execution (to break the loop) + +a<-1 +repeat{ + print("vibhu bhai tu kaisa hai") + if(a==5) + break + a<-a+1 +} \ No newline at end of file diff --git a/object classes.R b/object classes.R new file mode 100644 index 0000000..4842d1e --- /dev/null +++ b/object classes.R @@ -0,0 +1,40 @@ +gene=c("hspa1","hspa2","hspa3","hspa4","hspa5","hspa6") +amino.acids=c(125,365,254,654,158,369) +nucleotides=c(2400,2600,2500,2500,3600,2900) + +hsp=data.frame(gene,amino.acids,nucleotides) +print(hsp) + +print(gene) +print(hsp) + +class (hsp$gene) + +hsp$gene + +class(hsp$amino.acids) +hsp$nucleotides + +x=15+38 +x +class(x) + +z=as.character(c(1,2,3,4,5,6)) +z + +class(z) + + +z+x + +z2=c(1,2,3,4,5,6) +y2=c(9,8,7,6,5,4) + +z2+y2 + +class(y) + + +y=as.numeric(y) + + diff --git a/operator.R b/operator.R new file mode 100644 index 0000000..0873dd1 --- /dev/null +++ b/operator.R @@ -0,0 +1,61 @@ + +# operator ------------------------------------------------------------------- + +#arthmatic operator{ = - * / %% %/% ^} + +a<-45 +b<-36 +print(a+b) +print(a-b) +print(a*b) +print(a/b) +print(a%%b)#remainder +print(a%/%b)#quotient +print(a^b)#power of + + +c1<-c(2,4,55) +c2<-c(3,5,96) +#here c is vector this is for collection of similar type of datatypes + +print(c1+c2) +print(c1-c2) +print(c1*c2) +print(c1/c2) +print(c1%%c2) +print(c1%/%c2) +print(c1^c2) + + +#relational operator { < > <= >== == != } + +c1<-c(2,4,55) +c2<-c(3,5,96) + +print(c1c2) +print(c1<=c2) +print(c1>=c2) +print(c1!=c2) +print(c1==c2) + + +#logical operator{ & | ! && || } + + +c1<-c(2,4,55) +c2<-c(3,5,96) + +print(c1&c2) +print(c1&&c2) +print(c1!c2) +print(c1|c2) +print(c1||c2) + +# asignment operator {<- -> --> <--} + + + + + + diff --git a/practice.2.R b/practice.2.R new file mode 100644 index 0000000..eea07b3 --- /dev/null +++ b/practice.2.R @@ -0,0 +1,43 @@ +#next + +a<-1:10; +for (val in a) { + if(val == 5){ + next + } + print(val) + +} + +#break +a<-1 +repeat{ + print("vibhu bhai kaisa hai") + if(a==5) + break + a<-a+1 +} + + +#for loop + + for (val in 1:10) { + print(paste("number:,",val)) + # paste for concatanation of string + + } + + +f<-c("mango","banana","apple","pomgranate","orange","watermalon") +for (i in f) { + print(i) + print(f) + +} + + + + + + + diff --git a/practice.R b/practice.R new file mode 100644 index 0000000..d4d937d --- /dev/null +++ b/practice.R @@ -0,0 +1,10 @@ + +months=array(c("jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"),dim = (3:4)) +print(months) +months[2:4] + +months2=matrix(c("jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"),nrow = 3,ncol = 4) +months2 + +array3d=array(c(2,4,6,48,45,47,12,5,46,21,54,24,25,14,14,25),dim=c(3,3,2)) +print(array3d) \ No newline at end of file diff --git a/r functions.R b/r functions.R new file mode 100644 index 0000000..b17cd26 --- /dev/null +++ b/r functions.R @@ -0,0 +1,14 @@ +months=array(c("jan","feb","mar","apr","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"),dim=(c(3,4))) +months +#compare it to the simple list function +months1=c("jan","feb","mar","apr","mar","apr","may","jun","jly","aug","sep","oct","nov","dec") +months1 +months[2,4] + +# take a look into matrix +months2=matrix(data=c("jan","feb","mar","apr","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"),nrow=3,ncol=4) +months2 +#making a 3d array +array3d=array(c(2,3,4,5,10,12,14,16,18,20,22,1,26,28,30,32,34,36,38),dim = c(3,3,2)) +print(array3d) +array3d[1,2,3] \ No newline at end of file diff --git a/switch case.R b/switch case.R new file mode 100644 index 0000000..b7eea36 --- /dev/null +++ b/switch case.R @@ -0,0 +1,23 @@ +# switch case do tarah se implement kiya jata hai based on matching value and index value +#switch(expression,case1,case2,case3) + +#implementation based on index value +a<-switch(2, + "vibhu", + "singh", + "dadu", + "gaharwar" + + ) +print(a) + +# implementation based on matching value + +x<-"26" +y<-switch(x, + "26"="vibhu", + "25"="dadu", + "36"="gaharwar", + "29"="aakash" + ) +print(y) \ No newline at end of file diff --git a/variable.R b/variable.R new file mode 100644 index 0000000..eaaf455 --- /dev/null +++ b/variable.R @@ -0,0 +1,19 @@ +vibhu.singh<-45 +vibhu_singh<-35 +print(vibhu_singh) +print(vibhu.singh) +# r language me ham variables ke liye dot ya underscore use karte hai + + +#asignment of variables + +var1<-10 +var2=10 +10->var3 + + +#cat function combine multiple value to print output +# ye multiple values ko hold karke rakh sakta hai + + +cat(var1," ",var3) \ No newline at end of file diff --git a/vectors.R b/vectors.R new file mode 100644 index 0000000..302d8ff --- /dev/null +++ b/vectors.R @@ -0,0 +1,90 @@ +# data structure is a way to store data in a memory +#array +#vector +#array +#list +#matrix +#data frames + +#element of vector is known as component +#vector are two type ---->atomic vecrtor and list + +a<-c(4,3,6,9,8) +a +b<-c(4,5,5,6,7) +b +print(sum(a,b)) + + +a<-c(15,65,36,28,94) +a +b<--3:5 +b + + +sequ<-seq(1,5,length.out=7)# length out ka use karate hai values me gap laane ke liye +sequ + +x<-seq(1,3,by=.5) +x + +# atomic vector----numric vector,integear vector,character vector + + +a<-c(45L,36L,36L,65L) +print(class(a)) +#numeric to integer +q<-c(15,65,36,28,94) +q<-as.integer(q) +print(class(q)) + +#caharacter +b<-c(45,14,36,65) +b<-as.character(b) +a<-c("ram","shyam","mohan") +print(class(a)) + + +char.vec<-c("ram"=15,"shayam"=36,"mohan"=69) +char.vec[1:3] + +# agar hame kisi ko khojana hai indexing ki madad se tab hame sqaure braket use karna hota h +a1<-c(1,2,3,4,5) +a1[c(TRUE,FALSE,TRUE,FALSE,FALSE)] +# isame jo true honge wahi bas print kar ke dega + + + +#vector operation +a1<-c(45,14,36,65) +a2<-c(15,65,36,28) +a1+a2 +print(sum(a1,a2)) + +a3<-c("ram","syam","mohan","sohan") +a1<-c(45,14,36,65) +a4<-c(a1,a3) +a4 + + +a2<-c("ram","shayam","mohan","sohan") +a2[3] +a2[7] +f +a2[2:4] +a2[c(2,3,2,1,4)] + +#naming of vector +z<-c("ram","atul","mohan") +z +names(z)=c("y1","y2","y3") +z +print["y1"] + + + + + + + + diff --git a/while loop.R b/while loop.R new file mode 100644 index 0000000..bd83bdf --- /dev/null +++ b/while loop.R @@ -0,0 +1,9 @@ +v<-c("vibhu","singh","gaharwar") +x<-2 +#while loop me initialization pahle karna hota hai +while (x<=6){ + print(v) + x<-x+1#increment + + +} \ No newline at end of file