|
| 1 | +df=read.csv(url(http:/minerals.usgs.gov/alaska/economic/sewpen.html)) |
| 2 | +df=read.csv(url(http://minerals.usgs.gov/alaska/economic/sewpen.html)) |
| 3 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 4 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv")) |
| 5 | +View(df1) |
| 6 | +View(df2) |
| 7 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),drop=4) |
| 8 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 9 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=4) |
| 10 | +View(df2) |
| 11 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5) |
| 12 | +View(df2) |
| 13 | +View(df2) |
| 14 | +View(df1) |
| 15 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=6) |
| 16 | +View(df2) |
| 17 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".") |
| 18 | +View(df2) |
| 19 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".",na.strings = "Don`t remember") |
| 20 | +View(df2) |
| 21 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".",na.strings = "Don't remember") |
| 22 | +View(df1) |
| 23 | +View(df2) |
| 24 | +View(df1) |
| 25 | +View(df1) |
| 26 | +df=rbind(df1,df2) |
| 27 | +View(df2) |
| 28 | +View(df1) |
| 29 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 30 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".",na.strings = "Don't remember") |
| 31 | +df2$Observer=NA |
| 32 | +df=rbind(df1,df2[,-ncol(df2)]) |
| 33 | +View(df2) |
| 34 | +View(df1) |
| 35 | +View(df1) |
| 36 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 37 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".",na.strings = "Don't remember") |
| 38 | +df=rbind(df1[,-2],df2[,-ncol(df2)]) |
| 39 | +View(df1) |
| 40 | +View(df2) |
| 41 | +View(df2) |
| 42 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 43 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".",na.strings = "Don't remember") |
| 44 | +df=rbind(df1[,-2],df2) |
| 45 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 46 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".",na.strings = "Don't remember") |
| 47 | +names(df2)=names(df1[,-2]) |
| 48 | +df=rbind(df1[,-2],df2) |
| 49 | +summary(df) |
| 50 | +View(df1) |
| 51 | +View(df1) |
| 52 | +cv=names(df)[-(1:3)][c(T,F)] |
| 53 | +df$total=rowSums(df[,cv]) |
| 54 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 55 | +df2=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat2.csv"),skip=5,sep = ";",dec=".",na.strings = "Don't remember") |
| 56 | +names(df2)=names(df1[,-2]) |
| 57 | +df=rbind(df1[,-2],df2) |
| 58 | +df[,nrow(df)]=numeric(df[,nrow(df)]) |
| 59 | +df=rbind(df1[,-2],df2) |
| 60 | +df[,ncol(df)]=numeric(df[,col(df)]) |
| 61 | +df=rbind(df1[,-2],df2) |
| 62 | +df[,ncol(df)]=numeric(df[,ncol(df)]) |
| 63 | +df=rbind(df1[,-2],df2) |
| 64 | +df[,ncol(df)]=as.numeric(df[,ncol(df)]) |
| 65 | +cv=names(df)[-(1:3)][c(T,F)] |
| 66 | +df$total=rowSums(df[,cv]) |
| 67 | +summary(df$total) |
| 68 | +sapply(df[,endsWith(names(df),"Ht")], max) |
| 69 | +sort(sapply(df[,endsWith(names(df),"Ht")], max)) |
| 70 | +sort(-sapply(df[,endsWith(names(df),"Ht")], max)) |
| 71 | +sort(sapply(df[,endsWith(names(df),"Ht")], max),decreasing = T) |
| 72 | +df=df1[,c(1,endsWith(names(df),"Ht"))] |
| 73 | +View(df) |
| 74 | +View(df) |
| 75 | +df1=read.csv(url("https://github.com/tonytonov/Rcourse/raw/master/R%20programming/avianHabitat.csv")) |
| 76 | +View(df1) |
| 77 | +df=cbind(df1[,2],df1[,endsWith(names(df),"Ht")]) |
| 78 | +View(df) |
| 79 | +df=cbind(df1[,2],df1[,endsWith(names(df1),"Ht")]) |
| 80 | +View(df) |
| 81 | +vc=sapply(df[,-1], max) |
| 82 | +for(i in 2:ncol(df)){ |
| 83 | +print(df[which(df[,c(1,i)]==vc[i-1]),c(1,i)]) |
| 84 | +} |
| 85 | +tapply(df$PDB, df$Observer_name, max) |
| 86 | +View(df) |
| 87 | +vc=sapply(df[,-1], max) |
| 88 | +for(i in 2:ncol(df)){ |
| 89 | +k= which(df[,i]==vc[i-1]) |
| 90 | +print(df[k,c(1,i)]) |
| 91 | +} |
| 92 | +cat_temper <- c("задиристый", "игривый", "спокойный", "ленивый") |
| 93 | +cat_color <- c("белый", "серый", "чёрный", "рыжий") |
| 94 | +cat_age <- c("кот", "котёнок") |
| 95 | +cat_trait <- c("с умными глазами", "с острыми когтями", "с длинными усами") |
| 96 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait) |
| 97 | +#всевозможные комбинации |
| 98 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait, KEEP.OUT.ATTRS = TRUE) |
| 99 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait, KEEP.OUT.ATTRS = FALSE) |
| 100 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait)[42] |
| 101 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait)[42,] |
| 102 | +#всевозможные комбинации |
| 103 | +sort(expand.grid(cat_temper,cat_color,cat_age,cat_trait)) |
| 104 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait) %>% arrange(cat_temper,cat_color,cat_age,cat_trait) |
| 105 | +library(dplyr) |
| 106 | +#всевозможные комбинации |
| 107 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait) %>% arrange(cat_temper,cat_color,cat_age,cat_trait) |
| 108 | +library(dplyr) |
| 109 | +#всевозможные комбинации |
| 110 | +expand.grid(cat_temper,cat_color,cat_age,cat_trait) %>% |
| 111 | +arrange(cat_temper,cat_color,cat_age,cat_trait) |
| 112 | +library(stringi) |
| 113 | +#всевозможные комбинации |
| 114 | +expand.grid(stri_sort(cat_temper),stri_sort(cat_color),stri_sort(cat_age),stri_sort(cat_trait)) |
| 115 | +m=mapply(paste, d) |
| 116 | +library(stringi) |
| 117 | +#всевозможные комбинации |
| 118 | +d=expand.grid(cat_temper,cat_color,cat_age,cat_trait) |
| 119 | +m=mapply(paste, d) |
| 120 | +View(m) |
| 121 | +m=mapply(paste, d[[1]],d[[2]]) |
| 122 | +m=mapply(paste, d[[1:4]]) |
| 123 | +m=mapply(paste, d[,1:4]) |
| 124 | +m=mapply(paste, d[[1]],df[[2]],df[[3]],df[[4]]) |
| 125 | +d=expand.grid(cat_temper,cat_color,cat_age,cat_trait) |
| 126 | +m=mapply(paste, d[[1]],d[[2]],d[[3]],d[[4]]) |
| 127 | +sort(m) |
| 128 | +View(df1) |
| 129 | +View(df) |
| 130 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 131 | +View(df) |
| 132 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 133 | +names(df)[1:2]=c("P","S") |
| 134 | +View(df) |
| 135 | +df %>% group_by(P,S) %>% summarise_each(funs = function(x)max(x)>0) |
| 136 | +library(dplyr) |
| 137 | +df %>% group_by(P,S) %>% summarise_each(funs = function(x)max(x)>0) %>% sum |
| 138 | +View(df) |
| 139 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 140 | +names(df)[1:2]=c("P","S") |
| 141 | +df[,1]=apply(df[,1],1,function(t)stri_sub(t,length = length(t)-2)) |
| 142 | +apply(df[,1],1,function(t)stri_sub(t,length = length(t)-2)) |
| 143 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 144 | +names(df)[1:2]=c("P","S") |
| 145 | +df[,1]=apply(df[,1],1,function(t)stri_sub(t,length = nchar(t)-2)) |
| 146 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 147 | +names(df)[1:2]=c("P","S") |
| 148 | +df[,1] |
| 149 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 150 | +names(df)[1:2]=c("P","S") |
| 151 | +df=transform(df,P=stri_replace(df$P,"[:digit:]+","")) |
| 152 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 153 | +names(df)[1:2]=c("P","S") |
| 154 | +df=transform(df,P=factor(str_replace(df$P,"[:digit:]+","")) ) |
| 155 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 156 | +names(df)[1:2]=c("P","S") |
| 157 | +df=transform(df,P=factor(stri_replace(df$P,"[:digit:]+","")) ) |
| 158 | +df=transform(df,P=factor(stri_replace(.$P,"[:digit:]+","")) ) |
| 159 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 160 | +names(df)[1:2]=c("P","S") |
| 161 | +df=transform(df,P=factor(stri_replace(.$P,regex="[:digit:]+","")) ) |
| 162 | +df=cbind(df1[,1:2],df1[,endsWith(names(df1),"Ht")]) |
| 163 | +names(df)[1:2]=c("P","S") |
| 164 | +df=transform(df,P=factor(stri_replace(df$P,regex="[:digit:]+","")) ) |
| 165 | +View(df) |
| 166 | +library(dplyr) |
| 167 | +df %>% group_by(P,S) %>% summarise_each(funs = function(x)max(x)>0) |
| 168 | +df %>% group_by(P,S) %>% summarise_each(funs = function(x)sum(x>0)) |
0 commit comments