0% found this document useful (0 votes)
18 views2 pages

R Functions

This document lists various functions in R for working with directories, files, objects in memory, packages and help documentation. It also includes functions for importing and exporting data, working with dataframes like selecting rows/columns, sorting, merging, aggregating and manipulating data. Statistical and machine learning functions like lm(), glm(), scale(), hclust() and kmeans are also included.

Uploaded by

jazzymast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

R Functions

This document lists various functions in R for working with directories, files, objects in memory, packages and help documentation. It also includes functions for importing and exporting data, working with dataframes like selecting rows/columns, sorting, merging, aggregating and manipulating data. Statistical and machine learning functions like lm(), glm(), scale(), hclust() and kmeans are also included.

Uploaded by

jazzymast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Functions

1) getwd() gets current working directory


2) setwd(C:\Users\Abhishek\Desktop\R Sessions) change
working directory
3) list.files() lists all the files in the current working directory
4) (http://www.ats.ucla.edu/stat/r/faq/R_basics.htm)
5) ls() Lists all objects in the current workspace
6) rm(object), rm(object1, object2, func1) Removing objects from
workspace
7) rm(list=ls()) Removing all objects from the workspace
8) help(package = package_name) Open Documentation of a
package
9) ?fun_name or help(fun_name) Documentation of the function
10)
example(fun_name) Example of a function
11)
read.csv(file.choose(),header=T)
12)
install.packages(package_name)
13)
write.csv(data, file = "delact.csv")
14)
write.csv(seg,file="C:/Users/KARN/Desktop/CCD
Cafe/ABC.csv")
15)
c(a,b)
16)
x<- list(a,c(1,2), 123) ; x[[1]] ; names(x)<c("m","n","o")
17)
nrow() Number of rows in a dataframe
18)
ncol()
19)
head(dataframe)
20)
tail(dataframe)
21)
dim(dataframe) gives number of rows and columns in the
dataframe.
22)
str(dataframe) data types of variables
23)
names(dataframe)- Names of Variables
24)
colnames(dataframe)<- c(a,b)
25)
rownames(dataframe)<- c(a,b)
26)
data.frame(vector 1, vector 2)
27)
attach(dataframe)
28)
detach(dataframe)
29)
t(dataframe)
30)
iris[order(iris$Sepal.Length, iris$Sepal.Width),)] - Sorting
31)
View(dataframe)
32)
edit(dataframe)
33)
cbind(dataframe,vector,dataframe)
34)
rbind(dataframe,vector,dataframe)
35)
merge(dataframe1, dataframe2, by=variable,
all.dataframe2=T) Right Join

36)
detach(package:plyr) useful when 2 packages have
functions with same name
37)
aggregate(x1~year+month, data=df1, sum, na.rm=TRUE)
38)
sum(df1$x1[1:31])
39)
df2<-aggregate(cbind(x1, x2)~year+month, data=df1,
sum, na.rm=TRUE)
40)df2 <- ddply(df1, c("year", "month"), function(x) colSums(x[c("x1", "x2")]))
package(plyr)

41)
date=seq(as.Date("2000-01-01"),length=days,by="day")
42)
year(date)
43)
month(date)
44)
x1 = cumsum(rnorm(days,0.05))
45)
lm() For Linear Regression
46)
glm() For logistic regression
47)
scale() For normalizing the data
48)
hclust() Hierarchical Clustering
49)
kmeans- K- means Clustering
50)
ts() Converting a vector into time series object
51)
search()
52)
library()
53)
.libPaths()
54)
Library(hmisc) label(mydata$myvar)<-VAr
describe(mydata
55)
)

You might also like