0

I have a data frame of 9 columns and I want to delete a specific number from all numbers in column 6 but I don't want to ruin the structure of data frame. I want to deduct 383 from the column 6. How to do it?

my.data.frame11<-read.table("dir1/Water_Level/V3015010.txt",skip=4,header=T,sep=";")
head(my.data.frame11)

  X920 X1 V3015010 X19691027 X10.37 X480.000 X9 X2  X
1  920  1 V3015010  19691027  16:06      490  9  2 NA
2  920  1 V3015010  19691101  00:50      490  9  2 NA
3  920  1 V3015010  19691103  08:09      480  9  2 NA
4  920  1 V3015010  19691103  10:59      480  9  2 NA
5  920  1 V3015010  19691105  12:18      480  9  2 NA
6  920  1 V3015010  19691105  13:37      490  9  2 NA

If I use the following code

my.data.frame11[, 6] <- my.data.frame11[, 6] - 383

I got error:

Error in my.data.frame11[, 6] : incorrect number of dimensions

After I changed the header into false by the following command:

my.data.frame11[, 6] <- my.data.frame11[, 6] - 383

gave me the desired results. Thank you all for the help and having patience with me.

989
  • 12,579
  • 5
  • 31
  • 53
  • In column 6, there is no 383 in the example showed. what is your expected output? Do you want to change those 383 to NA? – akrun Jun 07 '16 at 12:33
  • I want to deduct from column 6 (480, 490, etc the following number 383) and than save it. – Nikola Pejakovic Jun 07 '16 at 12:37
  • Your title says `delete` now it is `deduct`. What exactly do you want? – akrun Jun 07 '16 at 12:38
  • Sorry for the usage of wrong words. I want to deduct the 383 from a specific column. – Nikola Pejakovic Jun 07 '16 at 12:40
  • Please show your expected output and also an example that have 383 – akrun Jun 07 '16 at 12:43
  • 1 920 1 V3015010 19691027 16:06 107 9 2 NA 2 920 1 V3015010 19691101 00:50 107 9 2 NA 3 920 1 V3015010 19691103 08:09 97 9 2 NA 4 920 1 V3015010 19691103 10:59 97 9 2 NA 5 920 1 V3015010 19691105 12:18 97 9 2 NA 6 920 1 V3015010 19691105 13:37 107 9 2 NA – Nikola Pejakovic Jun 07 '16 at 12:45
  • Please update it in your post. Can you read it from the comments? – akrun Jun 07 '16 at 12:45
  • 2
    Do you mean subtract 383 from every element of the column? That would be `df1[, 6] <- df1[, 6] - 383`. It's best to post such content in your question rather than in the comments. – lmo Jun 07 '16 at 12:45
  • Sorry I'm new here and I just getting familiar how to do things. – Nikola Pejakovic Jun 07 '16 at 12:46
  • Yes I want to subtract 383 from every element of the column witch is 65452 characters long. – Nikola Pejakovic Jun 07 '16 at 12:52
  • Welcome to Stack Overflow! Can you please include data and/or code that will provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? The code you posted looks like it *should* work, so there might be something funny about your data frame. At the very least, could we see the results of `str(my.dataframe11)`? (Also, you should probably be using `header=FALSE` when you read the data in ...) – Ben Bolker Jun 07 '16 at 12:54
  • Thank you all for the help. Ben Bolker thank you for the comment when I changed header to false I got the desiring results. Now I need to save this data to a new usable txt file. – Nikola Pejakovic Jun 07 '16 at 13:08

0 Answers0