I started with an empty df.
> df <- data.frame("coeff" = numeric(), "value" = numeric(), "Type" = character())
Now I added a few rows to this df in the following way.
> df<- rbind(df,c(0.05,sum(main$c1), "BaseLine"), stringsAsFactors = FALSE )
Note: main is another df, sum of col c1 need is added here. (nothing to worry about procedure up to this point). With this method, I added some rows to df. Since the last field in this code is character, rbind converted all columns into character.
I have two questions.
Is there a way around to use
rindwhere it does not follow thehierarchy: raw < logical < integer < double < complex < character < listas described inrbind help?Is there a way to convert all numeric class to character and retain values in character class without insertion of
NAs?
for eg. when using:
> sapply(df, as.numeric)the values in columnTypein thedfchanged toNAs.
I am looking for some function which would convert character fields containing numbers to numeric while leaving the character fields containing characters as it is.
I don't want to use:
df$coeff <- as.numeric(df$coeff)
df$value <- as.numeric(df$value)
because I have many columns and the number of columns changes everytime I read the input from ashapefile.