Search This Blog

Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Thursday, 15 June 2017

(R language) Text mining with R by using twitter dataset

library(tm)
library(twitteR)
library(RCurl)
library(wordcloud)

## twitter API authorization (You will get all these keys from your twitter account )
consumer_key<-'please insert your twitter account consumer_key'

(R language) k-means clustering

#k-means clustering
library(cluster)

#Read the dataset iris
iris2 <- iris

#Remove Species column for cluster
iris2$Species <- NULL

Friday, 3 March 2017

(R language) Switch function

x <- switch(1,"hi","sec","thr")        #here 1 vl return the first position value following 1
print(x)    
#output is [1] "hi"

x <- switch(0,"first","sec","thr")  #here 0 vl return the zero position value i.e there is no value at zero so it vl return nul
print(x)
#output is NULL

x <- switch(2,"name" = name<- readline(prompt = "enter name"),"c","thr")
print(x)
#output is [1] "c"

Wednesday, 1 March 2017

(R language) Multiple line code in list

multireturn <- function(x,y)
{
  mylist <- list("name" = name <- readline(prompt = "Enter Name"), x+y, if((x+y)%%2==0){print("Even")}else {print("odd")}  )
  return(mylist)
}
multireturn(2,3)