[R] Help sought with 1. converting factor to numeric; 2. creating new dataframe
Aditya Singh
aps6dl at yahoo.com
Tue Dec 16 12:25:19 CET 2014
Dear R-experts,
I am relatively new to R. Please help me in converting a dataframe into a numeric and then creating a new dataframe.
R-code attached:
my_xtrain=read.table("./train/X_train.txt")
my_xtest=read.table("./test/X_test.txt")
my_merge_data=merge(my_xtrain,my_xtest,all=TRUE)
### my_merge_datad is a new dataframe in which I want my_merge_data to be numeric
my_merge_datad=as.numeric(as.character(my_merge_data),na.rm=TRUE)
### my_m: I want to initialize a dataframe here
my_m=dat()
for (i in 1: 561) {
## here in my_m[1,i] I want to store the mean of all the columns, 1 to 561
my_m[1,i]= mean(my_merge_data[,i])
## here in my_m[2,i] that is the second row of the new dataframe my_m I want to store the standard deviation of columns 1 to ##561
my_m[2,i]=std(my_merge_data[,i])
}
Thanking you,
Aditya
More information about the R-help
mailing list