I would like to know how to muliply a single column by 5 from a txt file that I used a script to read. I only know how to mulitply all of the columns by a number, but not a single column. This is my script for reading the txt file:
d = read.table(file="tst1.txt",header=TRUE)
Lets suppose your dataframe d
has a column named "number" (you can see the actual names of the columns in the dataframe using str(d)
). To multiply the column "number" by 5, use:
# You are referring to the column "number" within the dataframe "d"
d$number * 5
# The last command only shoes the multiplication.
# If you want to replace the original values, use
d$number <- d$number * 5
# If you want to save the new values in a new column, use
d$numberX5 <- d$number * 5
Also, try referring to the standard R documentation, which you can find in the official page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With