ATA Tructures IN: Pavan Kumar A Senior Project Engineer Big Data Analytics Team Cdac-Kp
ATA Tructures IN: Pavan Kumar A Senior Project Engineer Big Data Analytics Team Cdac-Kp
ATA Tructures IN: Pavan Kumar A Senior Project Engineer Big Data Analytics Team Cdac-Kp
Pavan Kumar A
Senior Project Engineer
Big Data Analytics Team
CDAC-KP
DATA STRUCTURES IN R
> seq(4,9)#It generates the numbers from 4 to 9, only 2 arguments are given
[1] 4 5 6 7 8 9
> seq(4,10,2) #Three arguments are given, jump by 2 elements
[1] 4 6 8 10
Seq (1.65,1.90,0.05)
> 4:9
#exactly the same as seq(4,9)
[1] 4 5 6 7 8 9
> sum(1:10)
[1] 55
If you print a character vector, it usually comes out with quotes added to each
element. There is a way to avoid this, namely to use the cat() function.
For instance,
> cat(c("Huey","Dewey","Louie"))
Huey Dewey Louie>
> represents no new line character
To avoid this, and to get the system prompt next line:
> cat("Huey","Dewey","Louie", "\n")
Huey Dewey Louie
>
DATA STRUCTURES
IN
R- CHARACTER VECTORS
Example of c()
Syntax
matrix(data = NA, nrow = 1, ncol = 1,
byrow = FALSE)
You can glue vectors together, columnwise or rowwise, using the cbind and
rbind functions.
Arrays are similar to matrices but can have more than two dimensions.
See help(array) for details
Matrix Operations
We can extract the desired rows from the matrix
created as shown
Functions like rowSums() and rowMeans() are
used to calculate the sum of all row elements and
mean of all row elements respectively
Functions like colSums() and colMeans() are
used to calculate the mean of all column elements
and mean of all column elements respectively
Each column in the Data Frame can be a separate type of data. In the previous
example mydata data frame, it is the combination of numerical, character and
factor data types.
There are a variety of ways to identify the elements of a data frame. Here are
few screenshots.
IN
We can extract (subset) the part of the data table based on some condition
using subset() function
Syntax
Example
subset(x(dataset), function)
CREATING SUBSETS
IN
VECTORS
#Another vector
t<-c(one, one, two, three, four, two)
# Remove one entries
subset(t, t!=one)
t[t!=one]
CREATING SUBSETS
IN
VECTORS
Data Frames subsets can also be done using subset() and [] function
Data Frames subsets can also be done using subset() and [] function