type conversion - Change datatype of multiple columns in dataframe in R -
i have following dataframe:
str(dat2) data.frame: 29081 obs. of 105 variables: $ id: int 20 34 46 109 158.... $ reddit_id: chr "t1_cnas90f" "t1_cnas90t" "t1_cnas90g".... $ subreddit_id: chr "t5_cnas90f" "t5_cnas90t" "t5_cnas90g".... $ link_id: chr "t3_c2qy171" "t3_c2qy172" "t3_c2qy17f".... $ created_utc: chr "2015-01-01" "2015-01-01" "2015-01-01".... $ ups: int 3 1 0 1 2.... ...
how can change datatype of reddit_id, subreddit_id , link_id character factor? know how 1 column column, tedious work, searching faster way it.
i have tried following, without success:
dat2[2:4] <- data.frame(lapply(dat2[2:4], factor))
from this approach. end giving me error message: invalid "length" argument
another approach way:
dat2 <- as.factor(data.frame(dat2$reddit_id, dat2$subreddit_id, dat2$link_id))
result: error in sort.list(y): "x" must atomic "sort.
after reading error tried other way around:
dat2 <- data.frame(as.factor(dat2$reddit_id, dat2$subreddit_id, dat2$link_id))
also without success
if information missing, sorry. newbie r , stackoverflow...thank help!!!
Comments
Post a Comment