R is a programming language possesses an extensive catalog of statistical and graphical methods. It includes machine learning algorithm, linear regression, time series, statistical inference to name a few. Most of the R libraries are written in R,but many large companies also use R programming language, including Uber, Google, Airbnb, Facebook and so on

AD1

Email subscriptions

Enter your email address:

Delivered by FeedBurner

Showing posts with label data frame. Show all posts
Showing posts with label data frame. Show all posts

Wednesday, February 5, 2020

Data frame R

Data Frames

Dataframe


Data frame is similar to datasets SAS, SPSS and Stata. The data frame is created with R.
Data<- data.frame(col1, col2,col3,..), where col1,col2....... are column vectors. Data frames are close to what the analyst typically think of as data sets. There are several ways to identify the elements of a data frame. Here using the student data as a data frame.


> studentID <- c(1, 2, 3, 4)
> age <- c(25, 34, 28, 32)
> score <- c("Type1", "Type2", "Type1", "Type1")
> status <- c("Poor", "Improved", "Excellent", "Poor")
> studentdata <- data.frame(studentID, age, score, status)
> studentdata
  studentID age score    status
1         1  25 Type1      Poor
2         2  34 Type2  Improved
3         3  28 Type1 Excellent
4         4  32 Type1      Poor
> studentdata[1:2]
  studentID age
1         1  25
2         2  34
3         3  28
4         4  32
> studentdata[c("score", "status")]
  score    status
1 Type1      Poor
2 Type2  Improved
3 Type1 Excellent
4 Type1      Poor
> studentdata$age
[1] 25 34 28 32
> table(studentdata$score, studentdata$status)
     
        Excellent  Improved  Poor
  Type1         1        0           2
  Type2         0        1           0
studentdata <- data.frame(studentID, age, score, status,
+                           row.names=studentID)
Importing data from EXCEL
download and install the RODBC package
> install.packages("RODBC")
 channel <- odbcConnectExcel("myfile.xls")
Importing data from SPSS
install.packages("Hmisc")
 mydataframe <- spss.get("mydata.sav", use.value.labels=TRUE)
 Importing data from SAS
SAS program:
>     proc export data=mydata
>     outfile="mydata.csv"
>     dbms=csv;

>     run;

Friday, August 16, 2019

Types of data in R

There are many types of data in R

data types in r,r programming,r data types,data types,data types in r programming,data science,basic data types in r,different data types in r,r (programming language),r tutorial,types of data used in r programming,data,types of data,r programming tutorial,r programming for data science,learn r programming,data science with r,r programming language,r studio,data in r

Numeric
Example-1,2.0,23,123.5
Integer
Example- 1k,23L,230K
Complex
Example-2+6i,8+9i,1/(i-1)
Logical
Example- True, False
Character
Example:"c", "Mathematics", "2 plus 3."

R has basic data Structures

Vector

> c(1, 3, 5, 7, 8, 9)

[1] 1 3 5 7 8 9
> x = c(2, 4, 6, 8, 10, 12)
> c(46, "Mathematics", TRUE)
[1] "46"          "Mathematics" "TRUE" 
(y = 1:120)
  [1]   1   2   3   4   5   6   7   8   9  10
 [11]  11  12  13  14  15  16  17  18  19  20
 [21]  21  22  23  24  25  26  27  28  29  30
 [31]  31  32  33  34  35  36  37  38  39  40
 [41]  41  42  43  44  45  46  47  48  49  50
 [51]  51  52  53  54  55  56  57  58  59  60
 [61]  61  62  63  64  65  66  67  68  69  70
 [71]  71  72  73  74  75  76  77  78  79  80
 [81]  81  82  83  84  85  86  87  88  89  90
 [91]  91  92  93  94  95  96  97  98  99 100
[101] 101 102 103 104 105 106 107 108 109 110
[111] 111 112 113 114 115 116 117 118 119 120

>seq(from = 0.5, to = 4.2, by = 0.1)
 [1] 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4
[11] 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4
[21] 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4
[31] 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2
> c(x, rep(seq(1, 7, 2), 3), c(1, 2, 3), 46, 2:4)
 [1]  2  4  6  8 10 12  1  3  5  7  1  3  5  7
[15]  1  3  5  7  1  2  3 46  2  3  4
Matrix

> x = 1:8

> x
[1] 1 2 3 4 5 6 7 8
> Y = matrix(x, nrow = , ncol = 2, byrow = TRUE)
> y
  [1]   1   2   3   4   5   6   7   8   9  10
 [11]  11  12  13  14  15  16  17  18  19  20
 [21]  21  22  23  24  25  26  27  28  29  30
 [31]  31  32  33  34  35  36  37  38  39  40
 [41]  41  42  43  44  45  46  47  48  49  50
 [51]  51  52  53  54  55  56  57  58  59  60
 [61]  61  62  63  64  65  66  67  68  69  70
 [71]  71  72  73  74  75  76  77  78  79  80
 [81]  81  82  83  84  85  86  87  88  89  90
 [91]  91  92  93  94  95  96  97  98  99 100
[101] 101 102 103 104 105 106 107 108 109 110
[111] 111 112 113 114 115 116 117 118 119 120

List

list(40, "Hello", TRUE)

[[1]]
[1] 40

[[2]]
[1] "Hello"

[[3]]
[1] TRUE

Data Frame

> (test_sample = rnorm(n = 10, mean = 2, sd = 5))

 [1]  8.725094 -2.190330  2.573350 -7.649668
 [5]  6.420524  2.465019  4.561855 -8.622215
 [9]  7.883495  5.382970

a