In: Computer Science
How can I use the R language to code a new group to screen some variables? for example, there is a data set include 5 candy's brand: a b c d e
I just want to create a new group include a, b, c variable. How can I code it?
Solution: R is very good language for Statistical Applications and Graphical Presentation of data. It has capability to handle Vectors,Matrices,Lists,Dataframes as simple objects.
Here question contains a data set includes 5 candy's brands:a b c d e
Now creation of new group in R , it is easy as shown below:
# Creation of a dataset with five candy's brands as a data frame
brands<-c('a','b','c','d','e')
a<-c(1:10)
b<-seq(1,20, by=2)
c<-c(11:20)
d<-seq(1,30, by=3)
e<-c(21:30)
# Sample vectors created for a,b,c,d,e
candydataset<- data.farme(a,b,c,d,e)
candydataset<- data.frame(a,b,c,d,e)
> candydataset
a b c d e
1 1 1 11 1 21
2 2 3 12 4 22
3 3 5 13 7 23
4 4 7 14 10 24
5 5 9 15 13 25
6 6 11 16 16 26
7 7 13 17 19 27
8 8 15 18 22 28
9 9 17 19 25 29
10 10 19 20 28 30
if you want only 3 brands a,b,c we can create data frame with only
that vectors only as shown below:
Newcandy<-data.frame(a,b,c)
Newcandy
a b c
1 1 1 11
2 2 3 12
3 3 5 13
4 4 7 14
5 5 9 15
6 6 11 16
7 7 13 17
8 8 15 18
9 9 17 19
10 10 19 20
Note: I got the given question upto this extent. If i did not got your exact needs extreamly sorry.